forked from dchest/tweetnacl-js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnacl.min.js
1 lines (1 loc) · 17.9 KB
/
nacl.min.js
1
!function(i){var g=function(r,n){this.hi=0|r,this.lo=0|n},h=function(r){var n,e=new Float64Array(16);if(r)for(n=0;n<r.length;n++)e[n]=r[n];return e},a=function(){throw new Error("no PRNG")},C=new Uint8Array(16),t=new Uint8Array(32),c=(t[0]=9,h()),w=h([1]),F=h([56129,1]),Z=h([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),G=h([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),q=h([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),D=h([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),I=h([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function l(r,n){return r<<n|r>>>32-n}function s(r,n){return(((255&r[n+3])<<8|255&r[n+2])<<8|255&r[n+1])<<8|255&r[n+0]}function V(r,n){var e=r[n]<<24|r[n+1]<<16|r[n+2]<<8|r[n+3],r=r[n+4]<<24|r[n+5]<<16|r[n+6]<<8|r[n+7];return new g(e,r)}function v(r,n,e){for(var t=0;t<4;t++)r[n+t]=255&e,e>>>=8}function X(r,n,e){r[n]=e.hi>>24&255,r[n+1]=e.hi>>16&255,r[n+2]=e.hi>>8&255,r[n+3]=255&e.hi,r[n+4]=e.lo>>24&255,r[n+5]=e.lo>>16&255,r[n+6]=e.lo>>8&255,r[n+7]=255&e.lo}function o(r,n,e,t,o){for(var i=0,a=0;a<o;a++)i|=r[n+a]^e[t+a];return(1&i-1>>>8)-1}function j(r,n,e,t){return o(r,n,e,t,16)}function y(r,n,e,t){return o(r,n,e,t,32)}function H(r,n,e,t,o){for(var i,a,f=new Uint32Array(16),u=new Uint32Array(16),c=new Uint32Array(16),w=new Uint32Array(4),y=0;y<4;y++)u[5*y]=s(t,4*y),u[1+y]=s(e,4*y),u[6+y]=s(n,4*y),u[11+y]=s(e,16+4*y);for(y=0;y<16;y++)c[y]=u[y];for(y=0;y<20;y++){for(i=0;i<4;i++){for(a=0;a<4;a++)w[a]=u[(5*i+4*a)%16];for(w[1]^=l(w[0]+w[3]|0,7),w[2]^=l(w[1]+w[0]|0,9),w[3]^=l(w[2]+w[1]|0,13),w[0]^=l(w[3]+w[2]|0,18),a=0;a<4;a++)f[4*i+(i+a)%4]=w[a]}for(a=0;a<16;a++)u[a]=f[a]}if(o){for(y=0;y<16;y++)u[y]=u[y]+c[y]|0;for(y=0;y<4;y++)u[5*y]=u[5*y]-s(t,4*y)|0,u[6+y]=u[6+y]-s(n,4*y)|0;for(y=0;y<4;y++)v(r,4*y,u[5*y]),v(r,16+4*y,u[6+y])}else for(y=0;y<16;y++)v(r,4*y,u[y]+c[y]|0)}function J(r,n,e,t){H(r,n,e,t,!1)}function u(r,n,e,t){return H(r,n,e,t,!0),0}var b=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function p(r,n,e,t,o,i,a){var f,u,c=new Uint8Array(16),w=new Uint8Array(64);if(o){for(u=0;u<16;u++)c[u]=0;for(u=0;u<8;u++)c[u]=i[u];for(;64<=o;){for(J(w,c,a,b),u=0;u<64;u++)r[n+u]=(e?e[t+u]:0)^w[u];for(f=1,u=8;u<16;u++)f=f+(255&c[u])|0,c[u]=255&f,f>>>=8;o-=64,n+=64,e&&(t+=64)}if(0<o)for(J(w,c,a,b),u=0;u<o;u++)r[n+u]=(e?e[t+u]:0)^w[u]}return 0}function Q(r,n,e,t,o){return p(r,n,null,0,e,t,o)}function W(r,n,e,t,o){var i=new Uint8Array(32);return u(i,t,o,b),Q(r,n,e,t.subarray(16),i)}function f(r,n,e,t,o,i,a){var f=new Uint8Array(32);return u(f,i,a,b),p(r,n,e,t,o,i.subarray(16),f)}function $(r,n){for(var e=0,t=0;t<17;t++)e=e+(r[t]+n[t]|0)|0,r[t]=255&e,e>>>=8}var rr=new Uint32Array([5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,252]);function nr(r,n,e,t,o,i){for(var a,f,u,c=new Uint32Array(17),w=new Uint32Array(17),y=new Uint32Array(17),l=new Uint32Array(17),s=new Uint32Array(17),h=0;h<17;h++)w[h]=y[h]=0;for(h=0;h<16;h++)w[h]=i[h];for(w[3]&=15,w[4]&=252,w[7]&=15,w[8]&=252,w[11]&=15,w[12]&=252,w[15]&=15;0<o;){for(h=0;h<17;h++)l[h]=0;for(h=0;h<16&&h<o;++h)l[h]=e[t+h];for(l[h]=1,t+=h,o-=h,$(y,l),f=0;f<17;f++)for(h=c[f]=0;h<17;h++)c[f]=c[f]+y[h]*(h<=f?w[f-h]:320*w[f+17-h]|0)|0;for(f=0;f<17;f++)y[f]=c[f];for(h=u=0;h<16;h++)u=u+y[h]|0,y[h]=255&u,u>>>=8;for(u=u+y[16]|0,y[16]=3&u,u=5*(u>>>2)|0,h=0;h<16;h++)u=u+y[h]|0,y[h]=255&u,u>>>=8;u=u+y[16]|0,y[16]=u}for(h=0;h<17;h++)s[h]=y[h];for($(y,rr),a=0|-(y[16]>>>7),h=0;h<17;h++)y[h]^=a&(s[h]^y[h]);for(h=0;h<16;h++)l[h]=i[h+16];for(l[16]=0,$(y,l),h=0;h<16;h++)r[n+h]=y[h];return 0}function er(r,n,e,t,o,i){var a=new Uint8Array(16);return nr(a,0,e,t,o,i),j(r,n,a,0)}function tr(r,n,e,t,o){var i;if(e<32)return-1;for(f(r,0,n,0,e,t,o),nr(r,16,r,32,e-32,r),i=0;i<16;i++)r[i]=0;return 0}function or(r,n,e,t,o){var i,a=new Uint8Array(32);if(e<32)return-1;if(W(a,0,32,t,o),0!==er(n,16,n,32,e-32,a))return-1;for(f(r,0,n,0,e,t,o),i=0;i<32;i++)r[i]=0;return 0}function A(r,n){for(var e=0;e<16;e++)r[e]=0|n[e]}function _(r){for(var n,e=0;e<16;e++)r[e]+=65536,n=Math.floor(r[e]/65536),r[(e+1)*(e<15?1:0)]+=n-1+37*(n-1)*(15===e?1:0),r[e]-=65536*n}function U(r,n,e){for(var t,o=~(e-1),i=0;i<16;i++)t=o&(r[i]^n[i]),r[i]^=t,n[i]^=t}function E(r,n){for(var e,t,o=h(),i=h(),a=0;a<16;a++)i[a]=n[a];for(_(i),_(i),_(i),e=0;e<2;e++){for(o[0]=i[0]-65517,a=1;a<15;a++)o[a]=i[a]-65535-(o[a-1]>>16&1),o[a-1]&=65535;o[15]=i[15]-32767-(o[14]>>16&1),t=o[15]>>16&1,o[14]&=65535,U(i,o,1-t)}for(a=0;a<16;a++)r[2*a]=255&i[a],r[2*a+1]=i[a]>>8}function ir(r,n){var e=new Uint8Array(32),t=new Uint8Array(32);return E(e,r),E(t,n),y(e,0,t,0)}function ar(r){var n=new Uint8Array(32);return E(n,r),1&n[0]}function fr(r,n){for(var e=0;e<16;e++)r[e]=n[2*e]+(n[2*e+1]<<8);r[15]&=32767}function x(r,n,e){for(var t=0;t<16;t++)r[t]=n[t]+e[t]|0}function d(r,n,e){for(var t=0;t<16;t++)r[t]=n[t]-e[t]|0}function m(r,n,e){for(var t,o=new Float64Array(31),i=0;i<31;i++)o[i]=0;for(i=0;i<16;i++)for(t=0;t<16;t++)o[i+t]+=n[i]*e[t];for(i=0;i<15;i++)o[i]+=38*o[i+16];for(i=0;i<16;i++)r[i]=o[i];_(r),_(r)}function B(r,n){m(r,n,n)}function ur(r,n){for(var e=h(),t=0;t<16;t++)e[t]=n[t];for(t=253;0<=t;t--)B(e,e),2!==t&&4!==t&&m(e,e,n);for(t=0;t<16;t++)r[t]=e[t]}function cr(r,n){for(var e=h(),t=0;t<16;t++)e[t]=n[t];for(t=250;0<=t;t--)B(e,e),1!==t&&m(e,e,n);for(t=0;t<16;t++)r[t]=e[t]}function S(r,n,e){for(var t,o=new Uint8Array(32),i=new Float64Array(80),a=h(),f=h(),u=h(),c=h(),w=h(),y=h(),l=0;l<31;l++)o[l]=n[l];for(o[31]=127&n[31]|64,o[0]&=248,fr(i,e),l=0;l<16;l++)f[l]=i[l],c[l]=a[l]=u[l]=0;for(a[0]=c[0]=1,l=254;0<=l;--l)U(a,f,t=o[l>>>3]>>>(7&l)&1),U(u,c,t),x(w,a,u),d(a,a,u),x(u,f,c),d(f,f,c),B(c,w),B(y,a),m(a,u,a),m(u,f,w),x(w,a,u),d(a,a,u),B(f,a),d(u,c,y),m(a,u,F),x(a,a,c),m(u,u,a),m(a,c,y),m(c,f,i),B(f,w),U(a,f,t),U(u,c,t);for(l=0;l<16;l++)i[l+16]=a[l],i[l+32]=u[l],i[l+48]=f[l],i[l+64]=c[l];var e=i.subarray(32),s=i.subarray(16);return ur(e,e),m(s,s,e),E(r,s),0}function e(r,n){return S(r,n,t)}function wr(r,n){return a(n,32),e(r,n)}function K(r,n,e){var t=new Uint8Array(32);return S(t,e,n),u(r,C,t,b)}var yr=tr,lr=or;function Y(){for(var r,n=0,e=0,t=0,o=0,i=65535,a=0;a<arguments.length;a++)n+=(r=arguments[a].lo)&i,e+=r>>>16,t+=(r=arguments[a].hi)&i,o+=r>>>16;return new g((t+=(e+=n>>>16)>>>16)&i|(o+=t>>>16)<<16,n&i|e<<16)}function sr(r,n){return new g(r.hi>>>n,r.lo>>>n|r.hi<<32-n)}function L(){for(var r=0,n=0,e=0;e<arguments.length;e++)r^=arguments[e].lo,n^=arguments[e].hi;return new g(n,r)}function T(r,n){var e,t,o=32-n;return n<32?(e=r.hi>>>n|r.lo<<o,t=r.lo>>>n|r.hi<<o):n<64&&(e=r.lo>>>n|r.hi<<o,t=r.hi>>>n|r.lo<<o),new g(e,t)}var hr=[new g(1116352408,3609767458),new g(1899447441,602891725),new g(3049323471,3964484399),new g(3921009573,2173295548),new g(961987163,4081628472),new g(1508970993,3053834265),new g(2453635748,2937671579),new g(2870763221,3664609560),new g(3624381080,2734883394),new g(310598401,1164996542),new g(607225278,1323610764),new g(1426881987,3590304994),new g(1925078388,4068182383),new g(2162078206,991336113),new g(2614888103,633803317),new g(3248222580,3479774868),new g(3835390401,2666613458),new g(4022224774,944711139),new g(264347078,2341262773),new g(604807628,2007800933),new g(770255983,1495990901),new g(1249150122,1856431235),new g(1555081692,3175218132),new g(1996064986,2198950837),new g(2554220882,3999719339),new g(2821834349,766784016),new g(2952996808,2566594879),new g(3210313671,3203337956),new g(3336571891,1034457026),new g(3584528711,2466948901),new g(113926993,3758326383),new g(338241895,168717936),new g(666307205,1188179964),new g(773529912,1546045734),new g(1294757372,1522805485),new g(1396182291,2643833823),new g(1695183700,2343527390),new g(1986661051,1014477480),new g(2177026350,1206759142),new g(2456956037,344077627),new g(2730485921,1290863460),new g(2820302411,3158454273),new g(3259730800,3505952657),new g(3345764771,106217008),new g(3516065817,3606008344),new g(3600352804,1432725776),new g(4094571909,1467031594),new g(275423344,851169720),new g(430227734,3100823752),new g(506948616,1363258195),new g(659060556,3750685593),new g(883997877,3785050280),new g(958139571,3318307427),new g(1322822218,3812723403),new g(1537002063,2003034995),new g(1747873779,3602036899),new g(1955562222,1575990012),new g(2024104815,1125592928),new g(2227730452,2716904306),new g(2361852424,442776044),new g(2428436474,593698344),new g(2756734187,3733110249),new g(3204031479,2999351573),new g(3329325298,3815920427),new g(3391569614,3928383900),new g(3515267271,566280711),new g(3940187606,3454069534),new g(4118630271,4000239992),new g(116418474,1914138554),new g(174292421,2731055270),new g(289380356,3203993006),new g(460393269,320620315),new g(685471733,587496836),new g(852142971,1086792851),new g(1017036298,365543100),new g(1126000580,2618297676),new g(1288033470,3409855158),new g(1501505948,4234509866),new g(1607167915,987167468),new g(1816402316,1246189591)];function vr(r,n,e){for(var t,o=[],i=[],a=[],f=[],u=0;u<8;u++)o[u]=a[u]=V(r,8*u);for(var c,w,y,l,s,h,v=0;128<=e;){for(u=0;u<16;u++)f[u]=V(n,8*u+v);for(u=0;u<80;u++){for(t=0;t<8;t++)i[t]=a[t];for(y=Y(a[7],L(T(h=a[4],14),T(h,18),T(h,41)),(h=a[5],l=a[6],s=void 0,s=(y=a[4]).hi&h.hi^~y.hi&l.hi,h=y.lo&h.lo^~y.lo&l.lo,new g(s,h)),hr[u],f[u%16]),i[7]=Y(y,L(T(l=a[0],28),T(l,34),T(l,39)),(s=a[1],h=a[2],l=void 0,l=(w=a[0]).hi&s.hi^w.hi&h.hi^s.hi&h.hi,w=w.lo&s.lo^w.lo&h.lo^s.lo&h.lo,new g(l,w))),i[3]=Y(i[3],y),t=0;t<8;t++)a[(t+1)%8]=i[t];if(u%16==15)for(t=0;t<16;t++)f[t]=Y(f[t],f[(t+9)%16],L(T(c=f[(t+1)%16],1),T(c,8),sr(c,7)),L(T(c=f[(t+14)%16],19),T(c,61),sr(c,6)))}for(u=0;u<8;u++)a[u]=Y(a[u],o[u]),o[u]=a[u];v+=128,e-=128}for(u=0;u<8;u++)X(r,8*u,o[u])}var gr=new Uint8Array([106,9,230,103,243,188,201,8,187,103,174,133,132,202,167,59,60,110,243,114,254,148,248,43,165,79,245,58,95,29,54,241,81,14,82,127,173,230,130,209,155,5,104,140,43,62,108,31,31,131,217,171,251,65,189,107,91,224,205,25,19,126,33,121]);function k(r,n,e){for(var t=new Uint8Array(64),o=new Uint8Array(256),i=e,a=0;a<64;a++)t[a]=gr[a];for(vr(t,n,e),e%=128,a=0;a<256;a++)o[a]=0;for(a=0;a<e;a++)o[a]=n[i-e+a];for(o[e]=128,o[(e=256-128*(e<112?1:0))-9]=0,X(o,e-8,new g(i/536870912|0,i<<3)),vr(t,o,e),a=0;a<64;a++)r[a]=t[a];return 0}function z(r,n){var e=h(),t=h(),o=h(),i=h(),a=h(),f=h(),u=h(),c=h(),w=h();d(e,r[1],r[0]),d(w,n[1],n[0]),m(e,e,w),x(t,r[0],r[1]),x(w,n[0],n[1]),m(t,t,w),m(o,r[3],n[3]),m(o,o,G),m(i,r[2],n[2]),x(i,i,i),d(a,t,e),d(f,i,o),x(u,i,o),x(c,t,e),m(r[0],a,f),m(r[1],c,u),m(r[2],u,f),m(r[3],a,c)}function br(r,n,e){for(var t=0;t<4;t++)U(r[t],n[t],e)}function R(r,n){var e=h(),t=h(),o=h();ur(o,n[2]),m(e,n[0],o),m(t,n[1],o),E(r,t),r[31]^=ar(e)<<7}function pr(r,n,e){var t,o;for(A(r[0],c),A(r[1],w),A(r[2],w),A(r[3],c),o=255;0<=o;--o)br(r,n,t=e[o/8|0]>>(7&o)&1),z(n,r),z(r,r),br(r,n,t)}function P(r,n){var e=[h(),h(),h(),h()];A(e[0],q),A(e[1],D),A(e[2],w),m(e[3],q,D),pr(r,e,n)}function Ar(r,n,e){var t,o=new Uint8Array(64),i=[h(),h(),h(),h()];for(e||a(n,32),k(o,n,32),o[0]&=248,o[31]&=127,o[31]|=64,P(i,o),R(r,i),t=0;t<32;t++)n[t+32]=r[t];return 0}var M=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function _r(r,n){for(var e,t,o,i=63;32<=i;--i){for(e=0,t=i-32,o=i-12;t<o;++t)n[t]+=e-16*n[i]*M[t-(i-32)],e=Math.floor((n[t]+128)/256),n[t]-=256*e;n[t]+=e,n[i]=0}for(t=e=0;t<32;t++)n[t]+=e-(n[31]>>4)*M[t],e=n[t]>>8,n[t]&=255;for(t=0;t<32;t++)n[t]-=e*M[t];for(i=0;i<32;i++)n[i+1]+=n[i]>>8,r[i]=255&n[i]}function Ur(r){for(var n=new Float64Array(64),e=0;e<64;e++)n[e]=r[e];for(e=0;e<64;e++)r[e]=0;_r(r,n)}function Er(r,n,e,t){for(var o,i=new Uint8Array(64),a=new Uint8Array(64),f=new Uint8Array(64),u=new Float64Array(64),c=[h(),h(),h(),h()],w=(k(i,t,32),i[0]&=248,i[31]&=127,i[31]|=64,e+64),y=0;y<e;y++)r[64+y]=n[y];for(y=0;y<32;y++)r[32+y]=i[32+y];for(k(f,r.subarray(32),e+32),Ur(f),P(c,f),R(r,c),y=32;y<64;y++)r[y]=t[y];for(k(a,r,e+64),Ur(a),y=0;y<64;y++)u[y]=0;for(y=0;y<32;y++)u[y]=f[y];for(y=0;y<32;y++)for(o=0;o<32;o++)u[y+o]+=a[y]*i[o];return _r(r.subarray(32),u),w}function xr(r,n,e,t){var o,i=new Uint8Array(32),a=new Uint8Array(64),f=[h(),h(),h(),h()],u=[h(),h(),h(),h()];if(e<64)return-1;if(function(r,n){var e=h(),t=h(),o=h(),i=h(),a=h(),f=h(),u=h();if(A(r[2],w),fr(r[1],n),B(o,r[1]),m(i,o,Z),d(o,o,r[2]),x(i,r[2],i),B(a,i),B(f,a),m(u,f,a),m(e,u,o),m(e,e,i),cr(e,e),m(e,e,o),m(e,e,i),m(e,e,i),m(r[0],e,i),B(t,r[0]),m(t,t,i),ir(t,o)&&m(r[0],r[0],I),B(t,r[0]),m(t,t,i),ir(t,o))return 1;ar(r[0])===n[31]>>7&&d(r[0],c,r[0]),m(r[3],r[0],r[1])}(u,t))return-1;for(o=0;o<e;o++)r[o]=n[o];for(o=0;o<32;o++)r[o+32]=t[o];if(k(a,r,e),Ur(a),pr(f,u,a),P(u,n.subarray(32)),z(f,u),R(i,f),e-=64,y(n,0,i,0)){for(o=0;o<e;o++)r[o]=0;return-1}for(o=0;o<e;o++)r[o]=n[o+64];return e}var N;function dr(r,n){if(32!==r.length)throw new Error("bad key size");if(24!==n.length)throw new Error("bad nonce size")}function O(){for(var r=0;r<arguments.length;r++)if(!(arguments[r]instanceof Uint8Array))throw new TypeError("unexpected type, use Uint8Array")}function mr(r){for(var n=0;n<r.length;n++)r[n]=0}i.lowlevel={crypto_core_hsalsa20:u,crypto_stream_xor:f,crypto_stream:W,crypto_stream_salsa20_xor:p,crypto_stream_salsa20:Q,crypto_onetimeauth:nr,crypto_onetimeauth_verify:er,crypto_verify_16:j,crypto_verify_32:y,crypto_secretbox:tr,crypto_secretbox_open:or,crypto_scalarmult:S,crypto_scalarmult_base:e,crypto_box_beforenm:K,crypto_box_afternm:yr,crypto_box:function(r,n,e,t,o,i){var a=new Uint8Array(32);return K(a,o,i),yr(r,n,e,t,a)},crypto_box_open:function(r,n,e,t,o,i){var a=new Uint8Array(32);return K(a,o,i),lr(r,n,e,t,a)},crypto_box_keypair:wr,crypto_hash:k,crypto_sign:Er,crypto_sign_keypair:Ar,crypto_sign_open:xr,crypto_secretbox_KEYBYTES:32,crypto_secretbox_NONCEBYTES:24,crypto_secretbox_ZEROBYTES:32,crypto_secretbox_BOXZEROBYTES:16,crypto_scalarmult_BYTES:32,crypto_scalarmult_SCALARBYTES:32,crypto_box_PUBLICKEYBYTES:32,crypto_box_SECRETKEYBYTES:32,crypto_box_BEFORENMBYTES:32,crypto_box_NONCEBYTES:24,crypto_box_ZEROBYTES:32,crypto_box_BOXZEROBYTES:16,crypto_sign_BYTES:64,crypto_sign_PUBLICKEYBYTES:32,crypto_sign_SECRETKEYBYTES:64,crypto_sign_SEEDBYTES:32,crypto_hash_BYTES:64,gf:h,D:Z,L:M,pack:R,pack25519:E,unpack25519:fr,M:m,A:x,S:B,Z:d,pow2523:cr,add:z,set25519:A,modL:_r,scalarmult:pr,scalarbase:P},i.randomBytes=function(r){var n=new Uint8Array(r);return a(n,r),n},i.secretbox=function(r,n,e){O(r,n,e),dr(e,n);for(var t=new Uint8Array(32+r.length),o=new Uint8Array(t.length),i=0;i<r.length;i++)t[i+32]=r[i];return tr(o,t,t.length,n,e),o.subarray(16)},i.secretbox.open=function(r,n,e){O(r,n,e),dr(e,n);for(var t=new Uint8Array(16+r.length),o=new Uint8Array(t.length),i=0;i<r.length;i++)t[i+16]=r[i];return t.length<32||0!==or(o,t,t.length,n,e)?null:o.subarray(32)},i.secretbox.keyLength=32,i.secretbox.nonceLength=24,i.secretbox.overheadLength=16,i.scalarMult=function(r,n){if(O(r,n),32!==r.length)throw new Error("bad n size");if(32!==n.length)throw new Error("bad p size");var e=new Uint8Array(32);return S(e,r,n),e},i.scalarMult.base=function(r){if(O(r),32!==r.length)throw new Error("bad n size");var n=new Uint8Array(32);return e(n,r),n},i.scalarMult.scalarLength=32,i.scalarMult.groupElementLength=32,i.box=function(r,n,e,t){e=i.box.before(e,t);return i.secretbox(r,n,e)},i.box.before=function(r,n){O(r,n);var e=n;if(32!==r.length)throw new Error("bad public key size");if(32!==e.length)throw new Error("bad secret key size");e=new Uint8Array(32);return K(e,r,n),e},i.box.after=i.secretbox,i.box.open=function(r,n,e,t){e=i.box.before(e,t);return i.secretbox.open(r,n,e)},i.box.open.after=i.secretbox.open,i.box.keyPair=function(){var r=new Uint8Array(32),n=new Uint8Array(32);return wr(r,n),{publicKey:r,secretKey:n}},i.box.keyPair.fromSecretKey=function(r){if(O(r),32!==r.length)throw new Error("bad secret key size");var n=new Uint8Array(32);return e(n,r),{publicKey:n,secretKey:new Uint8Array(r)}},i.box.publicKeyLength=32,i.box.secretKeyLength=32,i.box.sharedKeyLength=32,i.box.nonceLength=24,i.box.overheadLength=i.secretbox.overheadLength,i.sign=function(r,n){if(O(r,n),64!==n.length)throw new Error("bad secret key size");var e=new Uint8Array(64+r.length);return Er(e,r,r.length,n),e},i.sign.open=function(r,n){if(O(r,n),32!==n.length)throw new Error("bad public key size");var e=new Uint8Array(r.length),r=xr(e,r,r.length,n);if(r<0)return null;for(var t=new Uint8Array(r),o=0;o<t.length;o++)t[o]=e[o];return t},i.sign.detached=function(r,n){for(var e=i.sign(r,n),t=new Uint8Array(64),o=0;o<t.length;o++)t[o]=e[o];return t},i.sign.detached.verify=function(r,n,e){if(O(r,n,e),64!==n.length)throw new Error("bad signature size");if(32!==e.length)throw new Error("bad public key size");for(var t=new Uint8Array(64+r.length),o=new Uint8Array(64+r.length),i=0;i<64;i++)t[i]=n[i];for(i=0;i<r.length;i++)t[i+64]=r[i];return 0<=xr(o,t,t.length,e)},i.sign.keyPair=function(){var r=new Uint8Array(32),n=new Uint8Array(64);return Ar(r,n),{publicKey:r,secretKey:n}},i.sign.keyPair.fromSecretKey=function(r){if(O(r),64!==r.length)throw new Error("bad secret key size");for(var n=new Uint8Array(32),e=0;e<n.length;e++)n[e]=r[32+e];return{publicKey:n,secretKey:new Uint8Array(r)}},i.sign.keyPair.fromSeed=function(r){if(O(r),32!==r.length)throw new Error("bad seed size");for(var n=new Uint8Array(32),e=new Uint8Array(64),t=0;t<32;t++)e[t]=r[t];return Ar(n,e,!0),{publicKey:n,secretKey:e}},i.sign.publicKeyLength=32,i.sign.secretKeyLength=64,i.sign.seedLength=32,i.sign.signatureLength=64,i.hash=function(r){O(r);var n=new Uint8Array(64);return k(n,r,r.length),n},i.hash.hashLength=64,i.verify=function(r,n){return O(r,n),0!==r.length&&0!==n.length&&r.length===n.length&&0===o(r,0,n,0,r.length)},i.setPRNG=function(r){a=r},(N="undefined"!=typeof self?self.crypto||self.msCrypto:null)&&N.getRandomValues?i.setPRNG(function(r,n){for(var e=new Uint8Array(n),t=0;t<n;t+=65536)N.getRandomValues(e.subarray(t,t+Math.min(n-t,65536)));for(t=0;t<n;t++)r[t]=e[t];mr(e)}):"undefined"!=typeof require&&(N=require("crypto"))&&N.randomBytes&&i.setPRNG(function(r,n){for(var e=N.randomBytes(n),t=0;t<n;t++)r[t]=e[t];mr(e)})}("undefined"!=typeof module&&module.exports?module.exports:self.nacl=self.nacl||{});