@blamejs/core 0.16.30 → 0.16.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/NOTICE +1 -1
- package/lib/vendor/MANIFEST.json +26 -26
- package/lib/vendor/noble-ciphers.cjs +792 -1
- package/lib/vendor/noble-curves.cjs +3443 -1
- package/lib/vendor/noble-post-quantum.cjs +2737 -1
- package/lib/vendor/pki.cjs +39550 -13
- package/lib/vendor/public-suffix-list.dat +4 -5
- package/lib/vendor/public-suffix-list.data.js +4363 -4363
- package/lib/vendor/simplewebauthn-server.cjs +22459 -32
- package/package.json +1 -1
- package/sbom.cdx.json +6 -6
|
@@ -1,7 +1,798 @@
|
|
|
1
1
|
// XChaCha20-Poly1305 — vendored from @noble/ciphers v2.2.0 by Paul Miller
|
|
2
2
|
// License: MIT — https://github.com/paulmillr/noble-ciphers
|
|
3
3
|
// Bundled with esbuild. Exports: xchacha20poly1305
|
|
4
|
-
var st=Object.defineProperty;var Ut=Object.getOwnPropertyDescriptor;var At=Object.getOwnPropertyNames;var Tt=Object.prototype.hasOwnProperty;var _t=(e,t)=>{for(var i in t)st(e,i,{get:t[i],enumerable:!0})},Ot=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of At(t))!Tt.call(e,s)&&s!==i&&st(e,s,{get:()=>t[s],enumerable:!(n=Ut(t,s))||n.enumerable});return e};var Rt=e=>Ot(st({},"__esModule",{value:!0}),e);var Vt={};_t(Vt,{xchacha20poly1305:()=>Bt});module.exports=Rt(Vt);function Ct(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function ft(e){if(typeof e!="boolean")throw new TypeError(`boolean expected, not ${e}`)}function tt(e){if(typeof e!="number")throw new TypeError("number expected, got "+typeof e);if(!Number.isSafeInteger(e)||e<0)throw new RangeError("positive integer expected, got "+e)}function j(e,t,i=""){let n=Ct(e),s=e?.length,o=t!==void 0;if(!n||o&&s!==t){let f=i&&`"${i}" `,r=o?` of length ${t}`:"",c=n?`length=${s}`:`type=${typeof e}`,u=f+"expected Uint8Array"+r+", got "+c;throw n?new RangeError(u):new TypeError(u)}return e}function it(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function at(e,t,i=!1){j(e,void 0,"output");let n=t.outputLen;if(e.length<n)throw new RangeError("digestInto() expects output buffer of length at least "+n);if(i&&!et(e))throw new Error("invalid output, must be aligned")}function q(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function V(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function It(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}var W=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68,lt=e=>e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255,k=W?e=>e:e=>lt(e)>>>0,St=e=>{for(let t=0;t<e.length;t++)e[t]=lt(e[t]);return e},F=W?e=>e:St;function ut(e,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(e,t)}function pt(e,t){if(e.length!==t.length)return!1;let i=0;for(let n=0;n<e.length;n++)i|=e[n]^t[n];return i===0}function yt(e,t,i){let n=t,s=i||(()=>[]),o=(r,c)=>n(c,...s(r)).update(r).digest(),f=n(new Uint8Array(e),...s(new Uint8Array(0)));return o.outputLen=f.outputLen,o.blockLen=f.blockLen,o.create=(r,...c)=>n(r,...c),o}var gt=(e,t)=>{function i(n,...s){if(j(n,void 0,"key"),e.nonceLength!==void 0){let l=s[0];j(l,e.varSizeNonce?void 0:e.nonceLength,"nonce")}let o=e.tagLength;o&&s[1]!==void 0&&j(s[1],void 0,"AAD");let f=t(n,...s),r=(l,y)=>{if(y!==void 0){if(l!==2)throw new Error("cipher output not supported");j(y,void 0,"output")}},c=!1;return{encrypt(l,y){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,j(l),r(f.encrypt.length,y),f.encrypt(l,y)},decrypt(l,y){if(j(l),o&&l.length<o)throw new Error('"ciphertext" expected length bigger than tagLength='+o);return r(f.decrypt.length,y),f.decrypt(l,y)}}}return Object.assign(i,e),i};function rt(e,t,i=!0){if(t===void 0)return new Uint8Array(e);if(j(t,void 0,"output"),t.length!==e)throw new Error('"output" expected Uint8Array of length '+e+", got: "+t.length);if(i&&!et(t))throw new Error("invalid output, must be aligned");return t}function xt(e,t,i){tt(e),tt(t),ft(i);let n=new Uint8Array(16),s=It(n);return s.setBigUint64(0,BigInt(t),i),s.setBigUint64(8,BigInt(e),i),n}function et(e){return e.byteOffset%4===0}function nt(e){return Uint8Array.from(j(e))}var wt=e=>Uint8Array.from(e.split(""),t=>t.charCodeAt(0)),vt=F(q(wt("expand 16-byte k"))),Nt=F(q(wt("expand 32-byte k")));function h(e,t){return e<<t|e>>>32-t}var ot=64,Mt=16,ct=2**32-1,dt=Uint32Array.of();function jt(e,t,i,n,s,o,f,r){let c=s.length,u=new Uint8Array(ot),l=q(u),y=W&&et(s)&&et(o),b=y?q(s):dt,w=y?q(o):dt;if(!W){for(let g=0;g<c;f++){if(e(t,i,n,l,f,r),F(l),f>=ct)throw new Error("arx: counter overflow");let x=Math.min(ot,c-g);for(let p=0,d;p<x;p++)d=g+p,o[d]=s[d]^u[p];g+=x}return}for(let g=0;g<c;f++){if(e(t,i,n,l,f,r),f>=ct)throw new Error("arx: counter overflow");let x=Math.min(ot,c-g);if(y&&x===ot){let p=g/4;if(g%4!==0)throw new Error("arx: invalid block position");for(let d=0,L;d<Mt;d++)L=p+d,w[L]=b[L]^l[d];g+=ot;continue}for(let p=0,d;p<x;p++)d=g+p,o[d]=s[d]^u[p];g+=x}}function bt(e,t){let{allowShortKeys:i,extendNonceFn:n,counterLength:s,counterRight:o,rounds:f}=ut({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!="function")throw new Error("core must be a function");return tt(s),tt(f),ft(o),ft(i),(r,c,u,l,y=0)=>{j(r,void 0,"key"),j(c,void 0,"nonce"),j(u,void 0,"data");let b=u.length;if(l=rt(b,l,!1),tt(y),y<0||y>=ct)throw new Error("arx: counter overflow");let w=[],g=r.length,x,p;if(g===32)w.push(x=nt(r)),p=Nt;else if(g===16&&i)x=new Uint8Array(32),x.set(r),x.set(r,16),p=vt,w.push(x);else throw j(r,32,"arx key"),new Error("invalid key size");(!W||!et(c))&&w.push(c=nt(c));let d=q(x);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");let M=c.subarray(0,16);if(W)n(p,d,q(M),d);else{let $=F(Uint32Array.from(p));n($,d,q(M),d),V($),F(d)}c=c.subarray(16)}else W||F(d);let L=16-s;if(L!==c.length)throw new Error(`arx: nonce must be ${L} or 16 bytes`);if(L!==12){let M=new Uint8Array(12);M.set(c,o?0:12-c.length),c=M,w.push(c)}let v=F(q(c));try{return jt(e,p,d,v,u,l,y,f),l}finally{V(...w)}}}function P(e,t){return e[t++]&255|(e[t++]&255)<<8}var ht=class{blockLen=16;outputLen=16;buffer=new Uint8Array(16);r=new Uint16Array(10);h=new Uint16Array(10);pad=new Uint16Array(8);pos=0;finished=!1;destroyed=!1;constructor(t){t=nt(j(t,32,"key"));let i=P(t,0),n=P(t,2),s=P(t,4),o=P(t,6),f=P(t,8),r=P(t,10),c=P(t,12),u=P(t,14);this.r[0]=i&8191,this.r[1]=(i>>>13|n<<3)&8191,this.r[2]=(n>>>10|s<<6)&7939,this.r[3]=(s>>>7|o<<9)&8191,this.r[4]=(o>>>4|f<<12)&255,this.r[5]=f>>>1&8190,this.r[6]=(f>>>14|r<<2)&8191,this.r[7]=(r>>>11|c<<5)&8065,this.r[8]=(c>>>8|u<<8)&8191,this.r[9]=u>>>5&127;for(let l=0;l<8;l++)this.pad[l]=P(t,16+2*l)}process(t,i,n=!1){let s=n?0:2048,{h:o,r:f}=this,r=f[0],c=f[1],u=f[2],l=f[3],y=f[4],b=f[5],w=f[6],g=f[7],x=f[8],p=f[9],d=P(t,i+0),L=P(t,i+2),v=P(t,i+4),M=P(t,i+6),$=P(t,i+8),z=P(t,i+10),H=P(t,i+12),K=P(t,i+14),m=o[0]+(d&8191),E=o[1]+((d>>>13|L<<3)&8191),B=o[2]+((L>>>10|v<<6)&8191),U=o[3]+((v>>>7|M<<9)&8191),A=o[4]+((M>>>4|$<<12)&8191),T=o[5]+($>>>1&8191),_=o[6]+(($>>>14|z<<2)&8191),O=o[7]+((z>>>11|H<<5)&8191),R=o[8]+((H>>>8|K<<8)&8191),C=o[9]+(K>>>5|s),a=0,S=a+m*r+E*(5*p)+B*(5*x)+U*(5*g)+A*(5*w);a=S>>>13,S&=8191,S+=T*(5*b)+_*(5*y)+O*(5*l)+R*(5*u)+C*(5*c),a+=S>>>13,S&=8191;let N=a+m*c+E*r+B*(5*p)+U*(5*x)+A*(5*g);a=N>>>13,N&=8191,N+=T*(5*w)+_*(5*b)+O*(5*y)+R*(5*l)+C*(5*u),a+=N>>>13,N&=8191;let I=a+m*u+E*c+B*r+U*(5*p)+A*(5*x);a=I>>>13,I&=8191,I+=T*(5*g)+_*(5*w)+O*(5*b)+R*(5*y)+C*(5*l),a+=I>>>13,I&=8191;let Y=a+m*l+E*u+B*c+U*r+A*(5*p);a=Y>>>13,Y&=8191,Y+=T*(5*x)+_*(5*g)+O*(5*w)+R*(5*b)+C*(5*y),a+=Y>>>13,Y&=8191;let Z=a+m*y+E*l+B*u+U*c+A*r;a=Z>>>13,Z&=8191,Z+=T*(5*p)+_*(5*x)+O*(5*g)+R*(5*w)+C*(5*b),a+=Z>>>13,Z&=8191;let G=a+m*b+E*y+B*l+U*u+A*c;a=G>>>13,G&=8191,G+=T*r+_*(5*p)+O*(5*x)+R*(5*g)+C*(5*w),a+=G>>>13,G&=8191;let Q=a+m*w+E*b+B*y+U*l+A*u;a=Q>>>13,Q&=8191,Q+=T*c+_*r+O*(5*p)+R*(5*x)+C*(5*g),a+=Q>>>13,Q&=8191;let J=a+m*g+E*w+B*b+U*y+A*l;a=J>>>13,J&=8191,J+=T*u+_*c+O*r+R*(5*p)+C*(5*x),a+=J>>>13,J&=8191;let X=a+m*x+E*g+B*w+U*b+A*y;a=X>>>13,X&=8191,X+=T*l+_*u+O*c+R*r+C*(5*p),a+=X>>>13,X&=8191;let D=a+m*p+E*x+B*g+U*w+A*b;a=D>>>13,D&=8191,D+=T*y+_*l+O*u+R*c+C*r,a+=D>>>13,D&=8191,a=(a<<2)+a|0,a=a+S|0,S=a&8191,a=a>>>13,N+=a,o[0]=S,o[1]=N,o[2]=I,o[3]=Y,o[4]=Z,o[5]=G,o[6]=Q,o[7]=J,o[8]=X,o[9]=D}finalize(){let{h:t,pad:i}=this,n=new Uint16Array(10),s=t[1]>>>13;t[1]&=8191;for(let r=2;r<10;r++)t[r]+=s,s=t[r]>>>13,t[r]&=8191;t[0]+=s*5,s=t[0]>>>13,t[0]&=8191,t[1]+=s,s=t[1]>>>13,t[1]&=8191,t[2]+=s,n[0]=t[0]+5,s=n[0]>>>13,n[0]&=8191;for(let r=1;r<10;r++)n[r]=t[r]+s,s=n[r]>>>13,n[r]&=8191;n[9]-=8192;let o=(s^1)-1;for(let r=0;r<10;r++)n[r]&=o;o=~o;for(let r=0;r<10;r++)t[r]=t[r]&o|n[r];t[0]=(t[0]|t[1]<<13)&65535,t[1]=(t[1]>>>3|t[2]<<10)&65535,t[2]=(t[2]>>>6|t[3]<<7)&65535,t[3]=(t[3]>>>9|t[4]<<4)&65535,t[4]=(t[4]>>>12|t[5]<<1|t[6]<<14)&65535,t[5]=(t[6]>>>2|t[7]<<11)&65535,t[6]=(t[7]>>>5|t[8]<<8)&65535,t[7]=(t[8]>>>8|t[9]<<5)&65535;let f=t[0]+i[0];t[0]=f&65535;for(let r=1;r<8;r++)f=(t[r]+i[r]|0)+(f>>>16)|0,t[r]=f&65535;V(n)}update(t){it(this),j(t),t=nt(t);let{buffer:i,blockLen:n}=this,s=t.length;for(let o=0;o<s;){let f=Math.min(n-this.pos,s-o);if(f===n){for(;n<=s-o;o+=n)this.process(t,o);continue}i.set(t.subarray(o,o+f),this.pos),this.pos+=f,o+=f,this.pos===n&&(this.process(i,0,!1),this.pos=0)}return this}destroy(){this.destroyed=!0,V(this.h,this.r,this.buffer,this.pad)}digestInto(t){it(this),at(t,this),this.finished=!0;let{buffer:i,h:n}=this,{pos:s}=this;if(s){for(i[s++]=1;s<16;s++)i[s]=0;this.process(i,0,!0)}this.finalize();let o=0;for(let f=0;f<8;f++)t[o++]=n[f]>>>0,t[o++]=n[f]>>>8}digest(){let{buffer:t,outputLen:i}=this;this.digestInto(t);let n=t.slice(0,i);return this.destroy(),n}},Lt=yt(32,e=>new ht(e));function kt(e,t,i,n,s,o=20){let f=e[0],r=e[1],c=e[2],u=e[3],l=t[0],y=t[1],b=t[2],w=t[3],g=t[4],x=t[5],p=t[6],d=t[7],L=s,v=i[0],M=i[1],$=i[2],z=f,H=r,K=c,m=u,E=l,B=y,U=b,A=w,T=g,_=x,O=p,R=d,C=L,a=v,S=M,N=$;for(let Y=0;Y<o;Y+=2)z=z+E|0,C=h(C^z,16),T=T+C|0,E=h(E^T,12),z=z+E|0,C=h(C^z,8),T=T+C|0,E=h(E^T,7),H=H+B|0,a=h(a^H,16),_=_+a|0,B=h(B^_,12),H=H+B|0,a=h(a^H,8),_=_+a|0,B=h(B^_,7),K=K+U|0,S=h(S^K,16),O=O+S|0,U=h(U^O,12),K=K+U|0,S=h(S^K,8),O=O+S|0,U=h(U^O,7),m=m+A|0,N=h(N^m,16),R=R+N|0,A=h(A^R,12),m=m+A|0,N=h(N^m,8),R=R+N|0,A=h(A^R,7),z=z+B|0,N=h(N^z,16),O=O+N|0,B=h(B^O,12),z=z+B|0,N=h(N^z,8),O=O+N|0,B=h(B^O,7),H=H+U|0,C=h(C^H,16),R=R+C|0,U=h(U^R,12),H=H+U|0,C=h(C^H,8),R=R+C|0,U=h(U^R,7),K=K+A|0,a=h(a^K,16),T=T+a|0,A=h(A^T,12),K=K+A|0,a=h(a^K,8),T=T+a|0,A=h(A^T,7),m=m+E|0,S=h(S^m,16),_=_+S|0,E=h(E^_,12),m=m+E|0,S=h(S^m,8),_=_+S|0,E=h(E^_,7);let I=0;n[I++]=f+z|0,n[I++]=r+H|0,n[I++]=c+K|0,n[I++]=u+m|0,n[I++]=l+E|0,n[I++]=y+B|0,n[I++]=b+U|0,n[I++]=w+A|0,n[I++]=g+T|0,n[I++]=x+_|0,n[I++]=p+O|0,n[I++]=d+R|0,n[I++]=L+C|0,n[I++]=v+a|0,n[I++]=M+S|0,n[I++]=$+N|0}function Pt(e,t,i,n){let s=k(e[0]),o=k(e[1]),f=k(e[2]),r=k(e[3]),c=k(t[0]),u=k(t[1]),l=k(t[2]),y=k(t[3]),b=k(t[4]),w=k(t[5]),g=k(t[6]),x=k(t[7]),p=k(i[0]),d=k(i[1]),L=k(i[2]),v=k(i[3]);for(let $=0;$<20;$+=2)s=s+c|0,p=h(p^s,16),b=b+p|0,c=h(c^b,12),s=s+c|0,p=h(p^s,8),b=b+p|0,c=h(c^b,7),o=o+u|0,d=h(d^o,16),w=w+d|0,u=h(u^w,12),o=o+u|0,d=h(d^o,8),w=w+d|0,u=h(u^w,7),f=f+l|0,L=h(L^f,16),g=g+L|0,l=h(l^g,12),f=f+l|0,L=h(L^f,8),g=g+L|0,l=h(l^g,7),r=r+y|0,v=h(v^r,16),x=x+v|0,y=h(y^x,12),r=r+y|0,v=h(v^r,8),x=x+v|0,y=h(y^x,7),s=s+u|0,v=h(v^s,16),g=g+v|0,u=h(u^g,12),s=s+u|0,v=h(v^s,8),g=g+v|0,u=h(u^g,7),o=o+l|0,p=h(p^o,16),x=x+p|0,l=h(l^x,12),o=o+l|0,p=h(p^o,8),x=x+p|0,l=h(l^x,7),f=f+y|0,d=h(d^f,16),b=b+d|0,y=h(y^b,12),f=f+y|0,d=h(d^f,8),b=b+d|0,y=h(y^b,7),r=r+c|0,L=h(L^r,16),w=w+L|0,c=h(c^w,12),r=r+c|0,L=h(L^r,8),w=w+L|0,c=h(c^w,7);let M=0;n[M++]=s,n[M++]=o,n[M++]=f,n[M++]=r,n[M++]=p,n[M++]=d,n[M++]=L,n[M++]=v,F(n)}var zt=bt(kt,{counterRight:!1,counterLength:8,extendNonceFn:Pt,allowShortKeys:!1});var Ht=new Uint8Array(16),mt=(e,t)=>{e.update(t);let i=t.length%16;i&&e.update(Ht.subarray(i))},Kt=new Uint8Array(32);function Et(e,t,i,n,s){s!==void 0&&j(s,void 0,"AAD");let o=e(t,i,Kt),f=xt(n.length,s?s.length:0,!0),r=Lt.create(o);s&&mt(r,s),mt(r,n),r.update(f);let c=r.digest();return V(o,f),c}var $t=e=>(t,i,n)=>({encrypt(o,f){let r=o.length;f=rt(r+16,f,!1),f.set(o);let c=f.subarray(0,-16);e(t,i,c,c,1);let u=Et(e,t,i,c,n);return f.set(u,r),V(u),f},decrypt(o,f){f=rt(o.length-16,f,!1);let r=o.subarray(0,-16),c=o.subarray(-16),u=Et(e,t,i,r,n);if(!pt(c,u))throw V(u),new Error("invalid tag");return f.set(o.subarray(0,-16)),e(t,i,f,f,1),V(u),f}});var Bt=gt({blockSize:64,nonceLength:24,tagLength:16},$t(zt));0&&(module.exports={xchacha20poly1305});
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// _entry.mjs
|
|
23
|
+
var entry_exports = {};
|
|
24
|
+
__export(entry_exports, {
|
|
25
|
+
xchacha20poly1305: () => xchacha20poly1305
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(entry_exports);
|
|
28
|
+
|
|
29
|
+
// node_modules/@noble/ciphers/utils.js
|
|
30
|
+
function isBytes(a) {
|
|
31
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
|
|
32
|
+
}
|
|
33
|
+
function abool(b) {
|
|
34
|
+
if (typeof b !== "boolean")
|
|
35
|
+
throw new TypeError(`boolean expected, not ${b}`);
|
|
36
|
+
}
|
|
37
|
+
function anumber(n) {
|
|
38
|
+
if (typeof n !== "number")
|
|
39
|
+
throw new TypeError("number expected, got " + typeof n);
|
|
40
|
+
if (!Number.isSafeInteger(n) || n < 0)
|
|
41
|
+
throw new RangeError("positive integer expected, got " + n);
|
|
42
|
+
}
|
|
43
|
+
function abytes(value, length, title = "") {
|
|
44
|
+
const bytes = isBytes(value);
|
|
45
|
+
const len = value?.length;
|
|
46
|
+
const needsLen = length !== void 0;
|
|
47
|
+
if (!bytes || needsLen && len !== length) {
|
|
48
|
+
const prefix = title && `"${title}" `;
|
|
49
|
+
const ofLen = needsLen ? ` of length ${length}` : "";
|
|
50
|
+
const got = bytes ? `length=${len}` : `type=${typeof value}`;
|
|
51
|
+
const message = prefix + "expected Uint8Array" + ofLen + ", got " + got;
|
|
52
|
+
if (!bytes)
|
|
53
|
+
throw new TypeError(message);
|
|
54
|
+
throw new RangeError(message);
|
|
55
|
+
}
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
function aexists(instance, checkFinished = true) {
|
|
59
|
+
if (instance.destroyed)
|
|
60
|
+
throw new Error("Hash instance has been destroyed");
|
|
61
|
+
if (checkFinished && instance.finished)
|
|
62
|
+
throw new Error("Hash#digest() has already been called");
|
|
63
|
+
}
|
|
64
|
+
function aoutput(out, instance, onlyAligned = false) {
|
|
65
|
+
abytes(out, void 0, "output");
|
|
66
|
+
const min = instance.outputLen;
|
|
67
|
+
if (out.length < min) {
|
|
68
|
+
throw new RangeError("digestInto() expects output buffer of length at least " + min);
|
|
69
|
+
}
|
|
70
|
+
if (onlyAligned && !isAligned32(out))
|
|
71
|
+
throw new Error("invalid output, must be aligned");
|
|
72
|
+
}
|
|
73
|
+
function u32(arr) {
|
|
74
|
+
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
75
|
+
}
|
|
76
|
+
function clean(...arrays) {
|
|
77
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
78
|
+
arrays[i].fill(0);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function createView(arr) {
|
|
82
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
83
|
+
}
|
|
84
|
+
var isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
85
|
+
var byteSwap = (word) => word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
86
|
+
var swap8IfBE = isLE ? (n) => n : (n) => byteSwap(n) >>> 0;
|
|
87
|
+
var byteSwap32 = (arr) => {
|
|
88
|
+
for (let i = 0; i < arr.length; i++)
|
|
89
|
+
arr[i] = byteSwap(arr[i]);
|
|
90
|
+
return arr;
|
|
91
|
+
};
|
|
92
|
+
var swap32IfBE = isLE ? (u) => u : byteSwap32;
|
|
93
|
+
function checkOpts(defaults, opts) {
|
|
94
|
+
if (opts == null || typeof opts !== "object")
|
|
95
|
+
throw new Error("options must be defined");
|
|
96
|
+
const merged = Object.assign(defaults, opts);
|
|
97
|
+
return merged;
|
|
98
|
+
}
|
|
99
|
+
function equalBytes(a, b) {
|
|
100
|
+
if (a.length !== b.length)
|
|
101
|
+
return false;
|
|
102
|
+
let diff = 0;
|
|
103
|
+
for (let i = 0; i < a.length; i++)
|
|
104
|
+
diff |= a[i] ^ b[i];
|
|
105
|
+
return diff === 0;
|
|
106
|
+
}
|
|
107
|
+
function wrapMacConstructor(keyLen, macCons, fromMsg) {
|
|
108
|
+
const mac = macCons;
|
|
109
|
+
const getArgs = fromMsg || (() => []);
|
|
110
|
+
const macC = (msg, key) => mac(key, ...getArgs(msg)).update(msg).digest();
|
|
111
|
+
const tmp = mac(new Uint8Array(keyLen), ...getArgs(new Uint8Array(0)));
|
|
112
|
+
macC.outputLen = tmp.outputLen;
|
|
113
|
+
macC.blockLen = tmp.blockLen;
|
|
114
|
+
macC.create = (key, ...args) => mac(key, ...args);
|
|
115
|
+
return macC;
|
|
116
|
+
}
|
|
117
|
+
var wrapCipher = /* @__NO_SIDE_EFFECTS__ */ (params, constructor) => {
|
|
118
|
+
function wrappedCipher(key, ...args) {
|
|
119
|
+
abytes(key, void 0, "key");
|
|
120
|
+
if (params.nonceLength !== void 0) {
|
|
121
|
+
const nonce = args[0];
|
|
122
|
+
abytes(nonce, params.varSizeNonce ? void 0 : params.nonceLength, "nonce");
|
|
123
|
+
}
|
|
124
|
+
const tagl = params.tagLength;
|
|
125
|
+
if (tagl && args[1] !== void 0)
|
|
126
|
+
abytes(args[1], void 0, "AAD");
|
|
127
|
+
const cipher = constructor(key, ...args);
|
|
128
|
+
const checkOutput = (fnLength, output) => {
|
|
129
|
+
if (output !== void 0) {
|
|
130
|
+
if (fnLength !== 2)
|
|
131
|
+
throw new Error("cipher output not supported");
|
|
132
|
+
abytes(output, void 0, "output");
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
let called = false;
|
|
136
|
+
const wrCipher = {
|
|
137
|
+
encrypt(data, output) {
|
|
138
|
+
if (called)
|
|
139
|
+
throw new Error("cannot encrypt() twice with same key + nonce");
|
|
140
|
+
called = true;
|
|
141
|
+
abytes(data);
|
|
142
|
+
checkOutput(cipher.encrypt.length, output);
|
|
143
|
+
return cipher.encrypt(data, output);
|
|
144
|
+
},
|
|
145
|
+
decrypt(data, output) {
|
|
146
|
+
abytes(data);
|
|
147
|
+
if (tagl && data.length < tagl)
|
|
148
|
+
throw new Error('"ciphertext" expected length bigger than tagLength=' + tagl);
|
|
149
|
+
checkOutput(cipher.decrypt.length, output);
|
|
150
|
+
return cipher.decrypt(data, output);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
return wrCipher;
|
|
154
|
+
}
|
|
155
|
+
Object.assign(wrappedCipher, params);
|
|
156
|
+
return wrappedCipher;
|
|
157
|
+
};
|
|
158
|
+
function getOutput(expectedLength, out, onlyAligned = true) {
|
|
159
|
+
if (out === void 0)
|
|
160
|
+
return new Uint8Array(expectedLength);
|
|
161
|
+
abytes(out, void 0, "output");
|
|
162
|
+
if (out.length !== expectedLength)
|
|
163
|
+
throw new Error('"output" expected Uint8Array of length ' + expectedLength + ", got: " + out.length);
|
|
164
|
+
if (onlyAligned && !isAligned32(out))
|
|
165
|
+
throw new Error("invalid output, must be aligned");
|
|
166
|
+
return out;
|
|
167
|
+
}
|
|
168
|
+
function u64Lengths(dataLength, aadLength, isLE2) {
|
|
169
|
+
anumber(dataLength);
|
|
170
|
+
anumber(aadLength);
|
|
171
|
+
abool(isLE2);
|
|
172
|
+
const num = new Uint8Array(16);
|
|
173
|
+
const view = createView(num);
|
|
174
|
+
view.setBigUint64(0, BigInt(aadLength), isLE2);
|
|
175
|
+
view.setBigUint64(8, BigInt(dataLength), isLE2);
|
|
176
|
+
return num;
|
|
177
|
+
}
|
|
178
|
+
function isAligned32(bytes) {
|
|
179
|
+
return bytes.byteOffset % 4 === 0;
|
|
180
|
+
}
|
|
181
|
+
function copyBytes(bytes) {
|
|
182
|
+
return Uint8Array.from(abytes(bytes));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// node_modules/@noble/ciphers/_arx.js
|
|
186
|
+
var encodeStr = (str) => Uint8Array.from(str.split(""), (c) => c.charCodeAt(0));
|
|
187
|
+
var sigma16_32 = /* @__PURE__ */ (() => swap32IfBE(u32(encodeStr("expand 16-byte k"))))();
|
|
188
|
+
var sigma32_32 = /* @__PURE__ */ (() => swap32IfBE(u32(encodeStr("expand 32-byte k"))))();
|
|
189
|
+
function rotl(a, b) {
|
|
190
|
+
return a << b | a >>> 32 - b;
|
|
191
|
+
}
|
|
192
|
+
var BLOCK_LEN = 64;
|
|
193
|
+
var BLOCK_LEN32 = 16;
|
|
194
|
+
var MAX_COUNTER = /* @__PURE__ */ (() => 2 ** 32 - 1)();
|
|
195
|
+
var U32_EMPTY = /* @__PURE__ */ Uint32Array.of();
|
|
196
|
+
function runCipher(core, sigma, key, nonce, data, output, counter, rounds) {
|
|
197
|
+
const len = data.length;
|
|
198
|
+
const block = new Uint8Array(BLOCK_LEN);
|
|
199
|
+
const b32 = u32(block);
|
|
200
|
+
const isAligned = isLE && isAligned32(data) && isAligned32(output);
|
|
201
|
+
const d32 = isAligned ? u32(data) : U32_EMPTY;
|
|
202
|
+
const o32 = isAligned ? u32(output) : U32_EMPTY;
|
|
203
|
+
if (!isLE) {
|
|
204
|
+
for (let pos = 0; pos < len; counter++) {
|
|
205
|
+
core(sigma, key, nonce, b32, counter, rounds);
|
|
206
|
+
swap32IfBE(b32);
|
|
207
|
+
if (counter >= MAX_COUNTER)
|
|
208
|
+
throw new Error("arx: counter overflow");
|
|
209
|
+
const take = Math.min(BLOCK_LEN, len - pos);
|
|
210
|
+
for (let j = 0, posj; j < take; j++) {
|
|
211
|
+
posj = pos + j;
|
|
212
|
+
output[posj] = data[posj] ^ block[j];
|
|
213
|
+
}
|
|
214
|
+
pos += take;
|
|
215
|
+
}
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
for (let pos = 0; pos < len; counter++) {
|
|
219
|
+
core(sigma, key, nonce, b32, counter, rounds);
|
|
220
|
+
if (counter >= MAX_COUNTER)
|
|
221
|
+
throw new Error("arx: counter overflow");
|
|
222
|
+
const take = Math.min(BLOCK_LEN, len - pos);
|
|
223
|
+
if (isAligned && take === BLOCK_LEN) {
|
|
224
|
+
const pos32 = pos / 4;
|
|
225
|
+
if (pos % 4 !== 0)
|
|
226
|
+
throw new Error("arx: invalid block position");
|
|
227
|
+
for (let j = 0, posj; j < BLOCK_LEN32; j++) {
|
|
228
|
+
posj = pos32 + j;
|
|
229
|
+
o32[posj] = d32[posj] ^ b32[j];
|
|
230
|
+
}
|
|
231
|
+
pos += BLOCK_LEN;
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
for (let j = 0, posj; j < take; j++) {
|
|
235
|
+
posj = pos + j;
|
|
236
|
+
output[posj] = data[posj] ^ block[j];
|
|
237
|
+
}
|
|
238
|
+
pos += take;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function createCipher(core, opts) {
|
|
242
|
+
const { allowShortKeys, extendNonceFn, counterLength, counterRight, rounds } = checkOpts({ allowShortKeys: false, counterLength: 8, counterRight: false, rounds: 20 }, opts);
|
|
243
|
+
if (typeof core !== "function")
|
|
244
|
+
throw new Error("core must be a function");
|
|
245
|
+
anumber(counterLength);
|
|
246
|
+
anumber(rounds);
|
|
247
|
+
abool(counterRight);
|
|
248
|
+
abool(allowShortKeys);
|
|
249
|
+
return (key, nonce, data, output, counter = 0) => {
|
|
250
|
+
abytes(key, void 0, "key");
|
|
251
|
+
abytes(nonce, void 0, "nonce");
|
|
252
|
+
abytes(data, void 0, "data");
|
|
253
|
+
const len = data.length;
|
|
254
|
+
output = getOutput(len, output, false);
|
|
255
|
+
anumber(counter);
|
|
256
|
+
if (counter < 0 || counter >= MAX_COUNTER)
|
|
257
|
+
throw new Error("arx: counter overflow");
|
|
258
|
+
const toClean = [];
|
|
259
|
+
let l = key.length;
|
|
260
|
+
let k;
|
|
261
|
+
let sigma;
|
|
262
|
+
if (l === 32) {
|
|
263
|
+
toClean.push(k = copyBytes(key));
|
|
264
|
+
sigma = sigma32_32;
|
|
265
|
+
} else if (l === 16 && allowShortKeys) {
|
|
266
|
+
k = new Uint8Array(32);
|
|
267
|
+
k.set(key);
|
|
268
|
+
k.set(key, 16);
|
|
269
|
+
sigma = sigma16_32;
|
|
270
|
+
toClean.push(k);
|
|
271
|
+
} else {
|
|
272
|
+
abytes(key, 32, "arx key");
|
|
273
|
+
throw new Error("invalid key size");
|
|
274
|
+
}
|
|
275
|
+
if (!isLE || !isAligned32(nonce))
|
|
276
|
+
toClean.push(nonce = copyBytes(nonce));
|
|
277
|
+
let k32 = u32(k);
|
|
278
|
+
if (extendNonceFn) {
|
|
279
|
+
if (nonce.length !== 24)
|
|
280
|
+
throw new Error(`arx: extended nonce must be 24 bytes`);
|
|
281
|
+
const n16 = nonce.subarray(0, 16);
|
|
282
|
+
if (isLE)
|
|
283
|
+
extendNonceFn(sigma, k32, u32(n16), k32);
|
|
284
|
+
else {
|
|
285
|
+
const sigmaRaw = swap32IfBE(Uint32Array.from(sigma));
|
|
286
|
+
extendNonceFn(sigmaRaw, k32, u32(n16), k32);
|
|
287
|
+
clean(sigmaRaw);
|
|
288
|
+
swap32IfBE(k32);
|
|
289
|
+
}
|
|
290
|
+
nonce = nonce.subarray(16);
|
|
291
|
+
} else if (!isLE)
|
|
292
|
+
swap32IfBE(k32);
|
|
293
|
+
const nonceNcLen = 16 - counterLength;
|
|
294
|
+
if (nonceNcLen !== nonce.length)
|
|
295
|
+
throw new Error(`arx: nonce must be ${nonceNcLen} or 16 bytes`);
|
|
296
|
+
if (nonceNcLen !== 12) {
|
|
297
|
+
const nc = new Uint8Array(12);
|
|
298
|
+
nc.set(nonce, counterRight ? 0 : 12 - nonce.length);
|
|
299
|
+
nonce = nc;
|
|
300
|
+
toClean.push(nonce);
|
|
301
|
+
}
|
|
302
|
+
const n32 = swap32IfBE(u32(nonce));
|
|
303
|
+
try {
|
|
304
|
+
runCipher(core, sigma, k32, n32, data, output, counter, rounds);
|
|
305
|
+
return output;
|
|
306
|
+
} finally {
|
|
307
|
+
clean(...toClean);
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// node_modules/@noble/ciphers/_poly1305.js
|
|
313
|
+
function u8to16(a, i) {
|
|
314
|
+
return a[i++] & 255 | (a[i++] & 255) << 8;
|
|
315
|
+
}
|
|
316
|
+
var Poly1305 = class {
|
|
317
|
+
blockLen = 16;
|
|
318
|
+
outputLen = 16;
|
|
319
|
+
buffer = new Uint8Array(16);
|
|
320
|
+
r = new Uint16Array(10);
|
|
321
|
+
// Allocating 1 array with .subarray() here is slower than 3
|
|
322
|
+
h = new Uint16Array(10);
|
|
323
|
+
pad = new Uint16Array(8);
|
|
324
|
+
pos = 0;
|
|
325
|
+
finished = false;
|
|
326
|
+
destroyed = false;
|
|
327
|
+
// Can be speed-up using BigUint64Array, at the cost of complexity
|
|
328
|
+
constructor(key) {
|
|
329
|
+
key = copyBytes(abytes(key, 32, "key"));
|
|
330
|
+
const t0 = u8to16(key, 0);
|
|
331
|
+
const t1 = u8to16(key, 2);
|
|
332
|
+
const t2 = u8to16(key, 4);
|
|
333
|
+
const t3 = u8to16(key, 6);
|
|
334
|
+
const t4 = u8to16(key, 8);
|
|
335
|
+
const t5 = u8to16(key, 10);
|
|
336
|
+
const t6 = u8to16(key, 12);
|
|
337
|
+
const t7 = u8to16(key, 14);
|
|
338
|
+
this.r[0] = t0 & 8191;
|
|
339
|
+
this.r[1] = (t0 >>> 13 | t1 << 3) & 8191;
|
|
340
|
+
this.r[2] = (t1 >>> 10 | t2 << 6) & 7939;
|
|
341
|
+
this.r[3] = (t2 >>> 7 | t3 << 9) & 8191;
|
|
342
|
+
this.r[4] = (t3 >>> 4 | t4 << 12) & 255;
|
|
343
|
+
this.r[5] = t4 >>> 1 & 8190;
|
|
344
|
+
this.r[6] = (t4 >>> 14 | t5 << 2) & 8191;
|
|
345
|
+
this.r[7] = (t5 >>> 11 | t6 << 5) & 8065;
|
|
346
|
+
this.r[8] = (t6 >>> 8 | t7 << 8) & 8191;
|
|
347
|
+
this.r[9] = t7 >>> 5 & 127;
|
|
348
|
+
for (let i = 0; i < 8; i++)
|
|
349
|
+
this.pad[i] = u8to16(key, 16 + 2 * i);
|
|
350
|
+
}
|
|
351
|
+
process(data, offset, isLast = false) {
|
|
352
|
+
const hibit = isLast ? 0 : 1 << 11;
|
|
353
|
+
const { h, r } = this;
|
|
354
|
+
const r0 = r[0];
|
|
355
|
+
const r1 = r[1];
|
|
356
|
+
const r2 = r[2];
|
|
357
|
+
const r3 = r[3];
|
|
358
|
+
const r4 = r[4];
|
|
359
|
+
const r5 = r[5];
|
|
360
|
+
const r6 = r[6];
|
|
361
|
+
const r7 = r[7];
|
|
362
|
+
const r8 = r[8];
|
|
363
|
+
const r9 = r[9];
|
|
364
|
+
const t0 = u8to16(data, offset + 0);
|
|
365
|
+
const t1 = u8to16(data, offset + 2);
|
|
366
|
+
const t2 = u8to16(data, offset + 4);
|
|
367
|
+
const t3 = u8to16(data, offset + 6);
|
|
368
|
+
const t4 = u8to16(data, offset + 8);
|
|
369
|
+
const t5 = u8to16(data, offset + 10);
|
|
370
|
+
const t6 = u8to16(data, offset + 12);
|
|
371
|
+
const t7 = u8to16(data, offset + 14);
|
|
372
|
+
let h0 = h[0] + (t0 & 8191);
|
|
373
|
+
let h1 = h[1] + ((t0 >>> 13 | t1 << 3) & 8191);
|
|
374
|
+
let h2 = h[2] + ((t1 >>> 10 | t2 << 6) & 8191);
|
|
375
|
+
let h3 = h[3] + ((t2 >>> 7 | t3 << 9) & 8191);
|
|
376
|
+
let h4 = h[4] + ((t3 >>> 4 | t4 << 12) & 8191);
|
|
377
|
+
let h5 = h[5] + (t4 >>> 1 & 8191);
|
|
378
|
+
let h6 = h[6] + ((t4 >>> 14 | t5 << 2) & 8191);
|
|
379
|
+
let h7 = h[7] + ((t5 >>> 11 | t6 << 5) & 8191);
|
|
380
|
+
let h8 = h[8] + ((t6 >>> 8 | t7 << 8) & 8191);
|
|
381
|
+
let h9 = h[9] + (t7 >>> 5 | hibit);
|
|
382
|
+
let c = 0;
|
|
383
|
+
let d0 = c + h0 * r0 + h1 * (5 * r9) + h2 * (5 * r8) + h3 * (5 * r7) + h4 * (5 * r6);
|
|
384
|
+
c = d0 >>> 13;
|
|
385
|
+
d0 &= 8191;
|
|
386
|
+
d0 += h5 * (5 * r5) + h6 * (5 * r4) + h7 * (5 * r3) + h8 * (5 * r2) + h9 * (5 * r1);
|
|
387
|
+
c += d0 >>> 13;
|
|
388
|
+
d0 &= 8191;
|
|
389
|
+
let d1 = c + h0 * r1 + h1 * r0 + h2 * (5 * r9) + h3 * (5 * r8) + h4 * (5 * r7);
|
|
390
|
+
c = d1 >>> 13;
|
|
391
|
+
d1 &= 8191;
|
|
392
|
+
d1 += h5 * (5 * r6) + h6 * (5 * r5) + h7 * (5 * r4) + h8 * (5 * r3) + h9 * (5 * r2);
|
|
393
|
+
c += d1 >>> 13;
|
|
394
|
+
d1 &= 8191;
|
|
395
|
+
let d2 = c + h0 * r2 + h1 * r1 + h2 * r0 + h3 * (5 * r9) + h4 * (5 * r8);
|
|
396
|
+
c = d2 >>> 13;
|
|
397
|
+
d2 &= 8191;
|
|
398
|
+
d2 += h5 * (5 * r7) + h6 * (5 * r6) + h7 * (5 * r5) + h8 * (5 * r4) + h9 * (5 * r3);
|
|
399
|
+
c += d2 >>> 13;
|
|
400
|
+
d2 &= 8191;
|
|
401
|
+
let d3 = c + h0 * r3 + h1 * r2 + h2 * r1 + h3 * r0 + h4 * (5 * r9);
|
|
402
|
+
c = d3 >>> 13;
|
|
403
|
+
d3 &= 8191;
|
|
404
|
+
d3 += h5 * (5 * r8) + h6 * (5 * r7) + h7 * (5 * r6) + h8 * (5 * r5) + h9 * (5 * r4);
|
|
405
|
+
c += d3 >>> 13;
|
|
406
|
+
d3 &= 8191;
|
|
407
|
+
let d4 = c + h0 * r4 + h1 * r3 + h2 * r2 + h3 * r1 + h4 * r0;
|
|
408
|
+
c = d4 >>> 13;
|
|
409
|
+
d4 &= 8191;
|
|
410
|
+
d4 += h5 * (5 * r9) + h6 * (5 * r8) + h7 * (5 * r7) + h8 * (5 * r6) + h9 * (5 * r5);
|
|
411
|
+
c += d4 >>> 13;
|
|
412
|
+
d4 &= 8191;
|
|
413
|
+
let d5 = c + h0 * r5 + h1 * r4 + h2 * r3 + h3 * r2 + h4 * r1;
|
|
414
|
+
c = d5 >>> 13;
|
|
415
|
+
d5 &= 8191;
|
|
416
|
+
d5 += h5 * r0 + h6 * (5 * r9) + h7 * (5 * r8) + h8 * (5 * r7) + h9 * (5 * r6);
|
|
417
|
+
c += d5 >>> 13;
|
|
418
|
+
d5 &= 8191;
|
|
419
|
+
let d6 = c + h0 * r6 + h1 * r5 + h2 * r4 + h3 * r3 + h4 * r2;
|
|
420
|
+
c = d6 >>> 13;
|
|
421
|
+
d6 &= 8191;
|
|
422
|
+
d6 += h5 * r1 + h6 * r0 + h7 * (5 * r9) + h8 * (5 * r8) + h9 * (5 * r7);
|
|
423
|
+
c += d6 >>> 13;
|
|
424
|
+
d6 &= 8191;
|
|
425
|
+
let d7 = c + h0 * r7 + h1 * r6 + h2 * r5 + h3 * r4 + h4 * r3;
|
|
426
|
+
c = d7 >>> 13;
|
|
427
|
+
d7 &= 8191;
|
|
428
|
+
d7 += h5 * r2 + h6 * r1 + h7 * r0 + h8 * (5 * r9) + h9 * (5 * r8);
|
|
429
|
+
c += d7 >>> 13;
|
|
430
|
+
d7 &= 8191;
|
|
431
|
+
let d8 = c + h0 * r8 + h1 * r7 + h2 * r6 + h3 * r5 + h4 * r4;
|
|
432
|
+
c = d8 >>> 13;
|
|
433
|
+
d8 &= 8191;
|
|
434
|
+
d8 += h5 * r3 + h6 * r2 + h7 * r1 + h8 * r0 + h9 * (5 * r9);
|
|
435
|
+
c += d8 >>> 13;
|
|
436
|
+
d8 &= 8191;
|
|
437
|
+
let d9 = c + h0 * r9 + h1 * r8 + h2 * r7 + h3 * r6 + h4 * r5;
|
|
438
|
+
c = d9 >>> 13;
|
|
439
|
+
d9 &= 8191;
|
|
440
|
+
d9 += h5 * r4 + h6 * r3 + h7 * r2 + h8 * r1 + h9 * r0;
|
|
441
|
+
c += d9 >>> 13;
|
|
442
|
+
d9 &= 8191;
|
|
443
|
+
c = (c << 2) + c | 0;
|
|
444
|
+
c = c + d0 | 0;
|
|
445
|
+
d0 = c & 8191;
|
|
446
|
+
c = c >>> 13;
|
|
447
|
+
d1 += c;
|
|
448
|
+
h[0] = d0;
|
|
449
|
+
h[1] = d1;
|
|
450
|
+
h[2] = d2;
|
|
451
|
+
h[3] = d3;
|
|
452
|
+
h[4] = d4;
|
|
453
|
+
h[5] = d5;
|
|
454
|
+
h[6] = d6;
|
|
455
|
+
h[7] = d7;
|
|
456
|
+
h[8] = d8;
|
|
457
|
+
h[9] = d9;
|
|
458
|
+
}
|
|
459
|
+
finalize() {
|
|
460
|
+
const { h, pad } = this;
|
|
461
|
+
const g = new Uint16Array(10);
|
|
462
|
+
let c = h[1] >>> 13;
|
|
463
|
+
h[1] &= 8191;
|
|
464
|
+
for (let i = 2; i < 10; i++) {
|
|
465
|
+
h[i] += c;
|
|
466
|
+
c = h[i] >>> 13;
|
|
467
|
+
h[i] &= 8191;
|
|
468
|
+
}
|
|
469
|
+
h[0] += c * 5;
|
|
470
|
+
c = h[0] >>> 13;
|
|
471
|
+
h[0] &= 8191;
|
|
472
|
+
h[1] += c;
|
|
473
|
+
c = h[1] >>> 13;
|
|
474
|
+
h[1] &= 8191;
|
|
475
|
+
h[2] += c;
|
|
476
|
+
g[0] = h[0] + 5;
|
|
477
|
+
c = g[0] >>> 13;
|
|
478
|
+
g[0] &= 8191;
|
|
479
|
+
for (let i = 1; i < 10; i++) {
|
|
480
|
+
g[i] = h[i] + c;
|
|
481
|
+
c = g[i] >>> 13;
|
|
482
|
+
g[i] &= 8191;
|
|
483
|
+
}
|
|
484
|
+
g[9] -= 1 << 13;
|
|
485
|
+
let mask = (c ^ 1) - 1;
|
|
486
|
+
for (let i = 0; i < 10; i++)
|
|
487
|
+
g[i] &= mask;
|
|
488
|
+
mask = ~mask;
|
|
489
|
+
for (let i = 0; i < 10; i++)
|
|
490
|
+
h[i] = h[i] & mask | g[i];
|
|
491
|
+
h[0] = (h[0] | h[1] << 13) & 65535;
|
|
492
|
+
h[1] = (h[1] >>> 3 | h[2] << 10) & 65535;
|
|
493
|
+
h[2] = (h[2] >>> 6 | h[3] << 7) & 65535;
|
|
494
|
+
h[3] = (h[3] >>> 9 | h[4] << 4) & 65535;
|
|
495
|
+
h[4] = (h[4] >>> 12 | h[5] << 1 | h[6] << 14) & 65535;
|
|
496
|
+
h[5] = (h[6] >>> 2 | h[7] << 11) & 65535;
|
|
497
|
+
h[6] = (h[7] >>> 5 | h[8] << 8) & 65535;
|
|
498
|
+
h[7] = (h[8] >>> 8 | h[9] << 5) & 65535;
|
|
499
|
+
let f = h[0] + pad[0];
|
|
500
|
+
h[0] = f & 65535;
|
|
501
|
+
for (let i = 1; i < 8; i++) {
|
|
502
|
+
f = (h[i] + pad[i] | 0) + (f >>> 16) | 0;
|
|
503
|
+
h[i] = f & 65535;
|
|
504
|
+
}
|
|
505
|
+
clean(g);
|
|
506
|
+
}
|
|
507
|
+
update(data) {
|
|
508
|
+
aexists(this);
|
|
509
|
+
abytes(data);
|
|
510
|
+
data = copyBytes(data);
|
|
511
|
+
const { buffer, blockLen } = this;
|
|
512
|
+
const len = data.length;
|
|
513
|
+
for (let pos = 0; pos < len; ) {
|
|
514
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
515
|
+
if (take === blockLen) {
|
|
516
|
+
for (; blockLen <= len - pos; pos += blockLen)
|
|
517
|
+
this.process(data, pos);
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
521
|
+
this.pos += take;
|
|
522
|
+
pos += take;
|
|
523
|
+
if (this.pos === blockLen) {
|
|
524
|
+
this.process(buffer, 0, false);
|
|
525
|
+
this.pos = 0;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
return this;
|
|
529
|
+
}
|
|
530
|
+
destroy() {
|
|
531
|
+
this.destroyed = true;
|
|
532
|
+
clean(this.h, this.r, this.buffer, this.pad);
|
|
533
|
+
}
|
|
534
|
+
digestInto(out) {
|
|
535
|
+
aexists(this);
|
|
536
|
+
aoutput(out, this);
|
|
537
|
+
this.finished = true;
|
|
538
|
+
const { buffer, h } = this;
|
|
539
|
+
let { pos } = this;
|
|
540
|
+
if (pos) {
|
|
541
|
+
buffer[pos++] = 1;
|
|
542
|
+
for (; pos < 16; pos++)
|
|
543
|
+
buffer[pos] = 0;
|
|
544
|
+
this.process(buffer, 0, true);
|
|
545
|
+
}
|
|
546
|
+
this.finalize();
|
|
547
|
+
let opos = 0;
|
|
548
|
+
for (let i = 0; i < 8; i++) {
|
|
549
|
+
out[opos++] = h[i] >>> 0;
|
|
550
|
+
out[opos++] = h[i] >>> 8;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
digest() {
|
|
554
|
+
const { buffer, outputLen } = this;
|
|
555
|
+
this.digestInto(buffer);
|
|
556
|
+
const res = buffer.slice(0, outputLen);
|
|
557
|
+
this.destroy();
|
|
558
|
+
return res;
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
var poly1305 = /* @__PURE__ */ wrapMacConstructor(32, (key) => new Poly1305(key));
|
|
562
|
+
|
|
563
|
+
// node_modules/@noble/ciphers/chacha.js
|
|
564
|
+
function chachaCore(s, k, n, out, cnt, rounds = 20) {
|
|
565
|
+
let y00 = s[0], y01 = s[1], y02 = s[2], y03 = s[3], y04 = k[0], y05 = k[1], y06 = k[2], y07 = k[3], y08 = k[4], y09 = k[5], y10 = k[6], y11 = k[7], y12 = cnt, y13 = n[0], y14 = n[1], y15 = n[2];
|
|
566
|
+
let x00 = y00, x01 = y01, x02 = y02, x03 = y03, x04 = y04, x05 = y05, x06 = y06, x07 = y07, x08 = y08, x09 = y09, x10 = y10, x11 = y11, x12 = y12, x13 = y13, x14 = y14, x15 = y15;
|
|
567
|
+
for (let r = 0; r < rounds; r += 2) {
|
|
568
|
+
x00 = x00 + x04 | 0;
|
|
569
|
+
x12 = rotl(x12 ^ x00, 16);
|
|
570
|
+
x08 = x08 + x12 | 0;
|
|
571
|
+
x04 = rotl(x04 ^ x08, 12);
|
|
572
|
+
x00 = x00 + x04 | 0;
|
|
573
|
+
x12 = rotl(x12 ^ x00, 8);
|
|
574
|
+
x08 = x08 + x12 | 0;
|
|
575
|
+
x04 = rotl(x04 ^ x08, 7);
|
|
576
|
+
x01 = x01 + x05 | 0;
|
|
577
|
+
x13 = rotl(x13 ^ x01, 16);
|
|
578
|
+
x09 = x09 + x13 | 0;
|
|
579
|
+
x05 = rotl(x05 ^ x09, 12);
|
|
580
|
+
x01 = x01 + x05 | 0;
|
|
581
|
+
x13 = rotl(x13 ^ x01, 8);
|
|
582
|
+
x09 = x09 + x13 | 0;
|
|
583
|
+
x05 = rotl(x05 ^ x09, 7);
|
|
584
|
+
x02 = x02 + x06 | 0;
|
|
585
|
+
x14 = rotl(x14 ^ x02, 16);
|
|
586
|
+
x10 = x10 + x14 | 0;
|
|
587
|
+
x06 = rotl(x06 ^ x10, 12);
|
|
588
|
+
x02 = x02 + x06 | 0;
|
|
589
|
+
x14 = rotl(x14 ^ x02, 8);
|
|
590
|
+
x10 = x10 + x14 | 0;
|
|
591
|
+
x06 = rotl(x06 ^ x10, 7);
|
|
592
|
+
x03 = x03 + x07 | 0;
|
|
593
|
+
x15 = rotl(x15 ^ x03, 16);
|
|
594
|
+
x11 = x11 + x15 | 0;
|
|
595
|
+
x07 = rotl(x07 ^ x11, 12);
|
|
596
|
+
x03 = x03 + x07 | 0;
|
|
597
|
+
x15 = rotl(x15 ^ x03, 8);
|
|
598
|
+
x11 = x11 + x15 | 0;
|
|
599
|
+
x07 = rotl(x07 ^ x11, 7);
|
|
600
|
+
x00 = x00 + x05 | 0;
|
|
601
|
+
x15 = rotl(x15 ^ x00, 16);
|
|
602
|
+
x10 = x10 + x15 | 0;
|
|
603
|
+
x05 = rotl(x05 ^ x10, 12);
|
|
604
|
+
x00 = x00 + x05 | 0;
|
|
605
|
+
x15 = rotl(x15 ^ x00, 8);
|
|
606
|
+
x10 = x10 + x15 | 0;
|
|
607
|
+
x05 = rotl(x05 ^ x10, 7);
|
|
608
|
+
x01 = x01 + x06 | 0;
|
|
609
|
+
x12 = rotl(x12 ^ x01, 16);
|
|
610
|
+
x11 = x11 + x12 | 0;
|
|
611
|
+
x06 = rotl(x06 ^ x11, 12);
|
|
612
|
+
x01 = x01 + x06 | 0;
|
|
613
|
+
x12 = rotl(x12 ^ x01, 8);
|
|
614
|
+
x11 = x11 + x12 | 0;
|
|
615
|
+
x06 = rotl(x06 ^ x11, 7);
|
|
616
|
+
x02 = x02 + x07 | 0;
|
|
617
|
+
x13 = rotl(x13 ^ x02, 16);
|
|
618
|
+
x08 = x08 + x13 | 0;
|
|
619
|
+
x07 = rotl(x07 ^ x08, 12);
|
|
620
|
+
x02 = x02 + x07 | 0;
|
|
621
|
+
x13 = rotl(x13 ^ x02, 8);
|
|
622
|
+
x08 = x08 + x13 | 0;
|
|
623
|
+
x07 = rotl(x07 ^ x08, 7);
|
|
624
|
+
x03 = x03 + x04 | 0;
|
|
625
|
+
x14 = rotl(x14 ^ x03, 16);
|
|
626
|
+
x09 = x09 + x14 | 0;
|
|
627
|
+
x04 = rotl(x04 ^ x09, 12);
|
|
628
|
+
x03 = x03 + x04 | 0;
|
|
629
|
+
x14 = rotl(x14 ^ x03, 8);
|
|
630
|
+
x09 = x09 + x14 | 0;
|
|
631
|
+
x04 = rotl(x04 ^ x09, 7);
|
|
632
|
+
}
|
|
633
|
+
let oi = 0;
|
|
634
|
+
out[oi++] = y00 + x00 | 0;
|
|
635
|
+
out[oi++] = y01 + x01 | 0;
|
|
636
|
+
out[oi++] = y02 + x02 | 0;
|
|
637
|
+
out[oi++] = y03 + x03 | 0;
|
|
638
|
+
out[oi++] = y04 + x04 | 0;
|
|
639
|
+
out[oi++] = y05 + x05 | 0;
|
|
640
|
+
out[oi++] = y06 + x06 | 0;
|
|
641
|
+
out[oi++] = y07 + x07 | 0;
|
|
642
|
+
out[oi++] = y08 + x08 | 0;
|
|
643
|
+
out[oi++] = y09 + x09 | 0;
|
|
644
|
+
out[oi++] = y10 + x10 | 0;
|
|
645
|
+
out[oi++] = y11 + x11 | 0;
|
|
646
|
+
out[oi++] = y12 + x12 | 0;
|
|
647
|
+
out[oi++] = y13 + x13 | 0;
|
|
648
|
+
out[oi++] = y14 + x14 | 0;
|
|
649
|
+
out[oi++] = y15 + x15 | 0;
|
|
650
|
+
}
|
|
651
|
+
function hchacha(s, k, i, out) {
|
|
652
|
+
let x00 = swap8IfBE(s[0]), x01 = swap8IfBE(s[1]), x02 = swap8IfBE(s[2]), x03 = swap8IfBE(s[3]), x04 = swap8IfBE(k[0]), x05 = swap8IfBE(k[1]), x06 = swap8IfBE(k[2]), x07 = swap8IfBE(k[3]), x08 = swap8IfBE(k[4]), x09 = swap8IfBE(k[5]), x10 = swap8IfBE(k[6]), x11 = swap8IfBE(k[7]), x12 = swap8IfBE(i[0]), x13 = swap8IfBE(i[1]), x14 = swap8IfBE(i[2]), x15 = swap8IfBE(i[3]);
|
|
653
|
+
for (let r = 0; r < 20; r += 2) {
|
|
654
|
+
x00 = x00 + x04 | 0;
|
|
655
|
+
x12 = rotl(x12 ^ x00, 16);
|
|
656
|
+
x08 = x08 + x12 | 0;
|
|
657
|
+
x04 = rotl(x04 ^ x08, 12);
|
|
658
|
+
x00 = x00 + x04 | 0;
|
|
659
|
+
x12 = rotl(x12 ^ x00, 8);
|
|
660
|
+
x08 = x08 + x12 | 0;
|
|
661
|
+
x04 = rotl(x04 ^ x08, 7);
|
|
662
|
+
x01 = x01 + x05 | 0;
|
|
663
|
+
x13 = rotl(x13 ^ x01, 16);
|
|
664
|
+
x09 = x09 + x13 | 0;
|
|
665
|
+
x05 = rotl(x05 ^ x09, 12);
|
|
666
|
+
x01 = x01 + x05 | 0;
|
|
667
|
+
x13 = rotl(x13 ^ x01, 8);
|
|
668
|
+
x09 = x09 + x13 | 0;
|
|
669
|
+
x05 = rotl(x05 ^ x09, 7);
|
|
670
|
+
x02 = x02 + x06 | 0;
|
|
671
|
+
x14 = rotl(x14 ^ x02, 16);
|
|
672
|
+
x10 = x10 + x14 | 0;
|
|
673
|
+
x06 = rotl(x06 ^ x10, 12);
|
|
674
|
+
x02 = x02 + x06 | 0;
|
|
675
|
+
x14 = rotl(x14 ^ x02, 8);
|
|
676
|
+
x10 = x10 + x14 | 0;
|
|
677
|
+
x06 = rotl(x06 ^ x10, 7);
|
|
678
|
+
x03 = x03 + x07 | 0;
|
|
679
|
+
x15 = rotl(x15 ^ x03, 16);
|
|
680
|
+
x11 = x11 + x15 | 0;
|
|
681
|
+
x07 = rotl(x07 ^ x11, 12);
|
|
682
|
+
x03 = x03 + x07 | 0;
|
|
683
|
+
x15 = rotl(x15 ^ x03, 8);
|
|
684
|
+
x11 = x11 + x15 | 0;
|
|
685
|
+
x07 = rotl(x07 ^ x11, 7);
|
|
686
|
+
x00 = x00 + x05 | 0;
|
|
687
|
+
x15 = rotl(x15 ^ x00, 16);
|
|
688
|
+
x10 = x10 + x15 | 0;
|
|
689
|
+
x05 = rotl(x05 ^ x10, 12);
|
|
690
|
+
x00 = x00 + x05 | 0;
|
|
691
|
+
x15 = rotl(x15 ^ x00, 8);
|
|
692
|
+
x10 = x10 + x15 | 0;
|
|
693
|
+
x05 = rotl(x05 ^ x10, 7);
|
|
694
|
+
x01 = x01 + x06 | 0;
|
|
695
|
+
x12 = rotl(x12 ^ x01, 16);
|
|
696
|
+
x11 = x11 + x12 | 0;
|
|
697
|
+
x06 = rotl(x06 ^ x11, 12);
|
|
698
|
+
x01 = x01 + x06 | 0;
|
|
699
|
+
x12 = rotl(x12 ^ x01, 8);
|
|
700
|
+
x11 = x11 + x12 | 0;
|
|
701
|
+
x06 = rotl(x06 ^ x11, 7);
|
|
702
|
+
x02 = x02 + x07 | 0;
|
|
703
|
+
x13 = rotl(x13 ^ x02, 16);
|
|
704
|
+
x08 = x08 + x13 | 0;
|
|
705
|
+
x07 = rotl(x07 ^ x08, 12);
|
|
706
|
+
x02 = x02 + x07 | 0;
|
|
707
|
+
x13 = rotl(x13 ^ x02, 8);
|
|
708
|
+
x08 = x08 + x13 | 0;
|
|
709
|
+
x07 = rotl(x07 ^ x08, 7);
|
|
710
|
+
x03 = x03 + x04 | 0;
|
|
711
|
+
x14 = rotl(x14 ^ x03, 16);
|
|
712
|
+
x09 = x09 + x14 | 0;
|
|
713
|
+
x04 = rotl(x04 ^ x09, 12);
|
|
714
|
+
x03 = x03 + x04 | 0;
|
|
715
|
+
x14 = rotl(x14 ^ x03, 8);
|
|
716
|
+
x09 = x09 + x14 | 0;
|
|
717
|
+
x04 = rotl(x04 ^ x09, 7);
|
|
718
|
+
}
|
|
719
|
+
let oi = 0;
|
|
720
|
+
out[oi++] = x00;
|
|
721
|
+
out[oi++] = x01;
|
|
722
|
+
out[oi++] = x02;
|
|
723
|
+
out[oi++] = x03;
|
|
724
|
+
out[oi++] = x12;
|
|
725
|
+
out[oi++] = x13;
|
|
726
|
+
out[oi++] = x14;
|
|
727
|
+
out[oi++] = x15;
|
|
728
|
+
swap32IfBE(out);
|
|
729
|
+
}
|
|
730
|
+
var xchacha20 = /* @__PURE__ */ createCipher(chachaCore, {
|
|
731
|
+
counterRight: false,
|
|
732
|
+
counterLength: 8,
|
|
733
|
+
extendNonceFn: hchacha,
|
|
734
|
+
allowShortKeys: false
|
|
735
|
+
});
|
|
736
|
+
var ZEROS16 = /* @__PURE__ */ new Uint8Array(16);
|
|
737
|
+
var updatePadded = (h, msg) => {
|
|
738
|
+
h.update(msg);
|
|
739
|
+
const leftover = msg.length % 16;
|
|
740
|
+
if (leftover)
|
|
741
|
+
h.update(ZEROS16.subarray(leftover));
|
|
742
|
+
};
|
|
743
|
+
var ZEROS32 = /* @__PURE__ */ new Uint8Array(32);
|
|
744
|
+
function computeTag(fn, key, nonce, ciphertext, AAD) {
|
|
745
|
+
if (AAD !== void 0)
|
|
746
|
+
abytes(AAD, void 0, "AAD");
|
|
747
|
+
const authKey = fn(key, nonce, ZEROS32);
|
|
748
|
+
const lengths = u64Lengths(ciphertext.length, AAD ? AAD.length : 0, true);
|
|
749
|
+
const h = poly1305.create(authKey);
|
|
750
|
+
if (AAD)
|
|
751
|
+
updatePadded(h, AAD);
|
|
752
|
+
updatePadded(h, ciphertext);
|
|
753
|
+
h.update(lengths);
|
|
754
|
+
const res = h.digest();
|
|
755
|
+
clean(authKey, lengths);
|
|
756
|
+
return res;
|
|
757
|
+
}
|
|
758
|
+
var _poly1305_aead = (xorStream) => (key, nonce, AAD) => {
|
|
759
|
+
const tagLength = 16;
|
|
760
|
+
return {
|
|
761
|
+
encrypt(plaintext, output) {
|
|
762
|
+
const plength = plaintext.length;
|
|
763
|
+
output = getOutput(plength + tagLength, output, false);
|
|
764
|
+
output.set(plaintext);
|
|
765
|
+
const oPlain = output.subarray(0, -tagLength);
|
|
766
|
+
xorStream(key, nonce, oPlain, oPlain, 1);
|
|
767
|
+
const tag = computeTag(xorStream, key, nonce, oPlain, AAD);
|
|
768
|
+
output.set(tag, plength);
|
|
769
|
+
clean(tag);
|
|
770
|
+
return output;
|
|
771
|
+
},
|
|
772
|
+
decrypt(ciphertext, output) {
|
|
773
|
+
output = getOutput(ciphertext.length - tagLength, output, false);
|
|
774
|
+
const data = ciphertext.subarray(0, -tagLength);
|
|
775
|
+
const passedTag = ciphertext.subarray(-tagLength);
|
|
776
|
+
const tag = computeTag(xorStream, key, nonce, data, AAD);
|
|
777
|
+
if (!equalBytes(passedTag, tag)) {
|
|
778
|
+
clean(tag);
|
|
779
|
+
throw new Error("invalid tag");
|
|
780
|
+
}
|
|
781
|
+
output.set(ciphertext.subarray(0, -tagLength));
|
|
782
|
+
xorStream(key, nonce, output, output, 1);
|
|
783
|
+
clean(tag);
|
|
784
|
+
return output;
|
|
785
|
+
}
|
|
786
|
+
};
|
|
787
|
+
};
|
|
788
|
+
var xchacha20poly1305 = /* @__PURE__ */ wrapCipher(
|
|
789
|
+
{ blockSize: 64, nonceLength: 24, tagLength: 16 },
|
|
790
|
+
/* @__PURE__ */ _poly1305_aead(xchacha20)
|
|
791
|
+
);
|
|
792
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
793
|
+
0 && (module.exports = {
|
|
794
|
+
xchacha20poly1305
|
|
795
|
+
});
|
|
5
796
|
/*! Bundled license information:
|
|
6
797
|
|
|
7
798
|
@noble/ciphers/utils.js:
|