-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTOTP.js
2 lines (2 loc) · 19.7 KB
/
TOTP.js
1
2
/* Minimised Javascript from https://stapp.space/generate-totp-in-postman/ */
var SUPPORTED_ALGS=15,X={};!function(r){"use strict";var e,n,t,o,i=4294967296;function w(r,e){this.highOrder=r,this.lowOrder=e}function h(r,e,n,t){var o,i,w,h="",u=e/8;for(w=-1===n?3:0,o=0;o<u;o+=1)i=r[o>>>2]>>>8*(w+n*(o%4)),h+="0123456789abcdef".charAt(i>>>4&15)+"0123456789abcdef".charAt(15&i);return t.outputUpper?h.toUpperCase():h}function u(r,e,n,t){var o,i,w,h,u,d,f="",a=e/8;for(d=-1===n?3:0,o=0;o<a;o+=3)for(h=o+1<a?r[o+1>>>2]:0,u=o+2<a?r[o+2>>>2]:0,w=(r[o>>>2]>>>8*(d+n*(o%4))&255)<<16|(h>>>8*(d+n*((o+1)%4))&255)<<8|u>>>8*(d+n*((o+2)%4))&255,i=0;i<4;i+=1)f+=8*o+6*i<=e?"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(w>>>6*(3-i)&63):t.b64Pad;return f}function d(r,e,n){var t,o,i,w="",h=e/8;for(i=-1===n?3:0,t=0;t<h;t+=1)o=r[t>>>2]>>>8*(i+n*(t%4))&255,w+=String.fromCharCode(o);return w}function f(r,e,n){var t,o,i,w=e/8,h=new ArrayBuffer(w);for(i=new Uint8Array(h),o=-1===n?3:0,t=0;t<w;t+=1)i[t]=r[t>>>2]>>>8*(o+n*(t%4))&255;return h}function a(r){var e,n={outputUpper:!1,b64Pad:"=",shakeLen:-1};if(e=r||{},n.outputUpper=e.outputUpper||!1,!0===e.hasOwnProperty("b64Pad")&&(n.b64Pad=e.b64Pad),!0===e.hasOwnProperty("shakeLen")&&0!=(8&SUPPORTED_ALGS)){if(e.shakeLen%8!=0)throw new Error("shakeLen must be a multiple of 8");n.shakeLen=e.shakeLen}if("boolean"!=typeof n.outputUpper)throw new Error("Invalid outputUpper formatting option");if("string"!=typeof n.b64Pad)throw new Error("Invalid b64Pad formatting option");return n}function O(r,e,n){var t;switch(e){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(r){case"HEX":t=function(r,e,t){return function(r,e,n,t){var o,i,w,h,u,d,f,a=r.length;if(0!=a%2)throw new Error("String of HEX type must be in byte increments");for(o=e||[0],d=(n=n||0)>>>3,f=-1===t?3:0,i=0;i<a;i+=2){if(w=parseInt(r.substr(i,2),16),isNaN(w))throw new Error("String of HEX type contains invalid characters");for(h=(u=(i>>>1)+d)>>>2;o.length<=h;)o.push(0);o[h]|=w<<8*(f+t*(u%4))}return{value:o,binLen:4*a+n}}(r,e,t,n)};break;case"TEXT":t=function(r,t,o){return function(r,e,n,t,o){var i,w,h,u,d,f,a,O,l,s,c=0;if(i=n||[0],f=(t=t||0)>>>3,"UTF8"===e)for(l=-1===o?3:0,u=0;u<r.length;u+=1)for(h=[],128>(w=r.charCodeAt(u))?h.push(w):2048>w?(h.push(192|w>>>6),h.push(128|63&w)):55296>w||57344<=w?h.push(224|w>>>12,128|w>>>6&63,128|63&w):(u+=1,w=65536+((1023&w)<<10|1023&r.charCodeAt(u)),h.push(240|w>>>18,128|w>>>12&63,128|w>>>6&63,128|63&w)),d=0;d<h.length;d+=1){for(a=(O=c+f)>>>2;i.length<=a;)i.push(0);i[a]|=h[d]<<8*(l+o*(O%4)),c+=1}else if("UTF16BE"===e||"UTF16LE"===e)for(l=-1===o?2:0,s="UTF16LE"===e&&1!==o||"UTF16LE"!==e&&1===o,u=0;u<r.length;u+=1){for(w=r.charCodeAt(u),!0===s&&(w=(d=255&w)<<8|w>>>8),a=(O=c+f)>>>2;i.length<=a;)i.push(0);i[a]|=w<<8*(l+o*(O%4)),c+=2}return{value:i,binLen:8*c+t}}(r,e,t,o,n)};break;case"B64":t=function(r,e,t){return function(r,e,n,t){var o,i,w,h,u,d,f,a,O,l,s=0;if(-1===r.search(/^[a-zA-Z0-9=+\/]+$/))throw new Error("Invalid character in base-64 string");if(d=r.indexOf("="),r=r.replace(/\=/g,""),-1!==d&&d<r.length)throw new Error("Invalid '=' found in base-64 string");for(o=e||[0],f=(n=n||0)>>>3,l=-1===t?3:0,i=0;i<r.length;i+=4){for(u=r.substr(i,4),h=0,w=0;w<u.length;w+=1)h|="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(u[w])<<18-6*w;for(w=0;w<u.length-1;w+=1){for(a=(O=s+f)>>>2;o.length<=a;)o.push(0);o[a]|=(h>>>16-8*w&255)<<8*(l+t*(O%4)),s+=1}}return{value:o,binLen:8*s+n}}(r,e,t,n)};break;case"BYTES":t=function(r,e,t){return function(r,e,n,t){var o,i,w,h,u,d,f;for(o=e||[0],h=(n=n||0)>>>3,f=-1===t?3:0,w=0;w<r.length;w+=1)i=r.charCodeAt(w),u=(d=w+h)>>>2,o.length<=u&&o.push(0),o[u]|=i<<8*(f+t*(d%4));return{value:o,binLen:8*r.length+n}}(r,e,t,n)};break;case"ARRAYBUFFER":try{t=new ArrayBuffer(0)}catch(r){throw new Error("ARRAYBUFFER not supported by this environment")}t=function(r,e,t){return function(r,e,n,t){var o,i,w,h,u,d,f;for(o=e||[0],w=(n=n||0)>>>3,d=-1===t?3:0,f=new Uint8Array(r),i=0;i<r.byteLength;i+=1)h=(u=i+w)>>>2,o.length<=h&&o.push(0),o[h]|=f[i]<<8*(d+t*(u%4));return{value:o,binLen:8*r.byteLength+n}}(r,e,t,n)};break;default:throw new Error("format must be HEX, TEXT, B64, BYTES, or ARRAYBUFFER")}return t}function l(r,e){return r<<e|r>>>32-e}function s(r,e){return e>32?(e-=32,new w(r.lowOrder<<e|r.highOrder>>>32-e,r.highOrder<<e|r.lowOrder>>>32-e)):0!==e?new w(r.highOrder<<e|r.lowOrder>>>32-e,r.lowOrder<<e|r.highOrder>>>32-e):r}function c(r,e){return r>>>e|r<<32-e}function g(r,e){var n=new w(r.highOrder,r.lowOrder);return 32>=e?new w(n.highOrder>>>e|n.lowOrder<<32-e&4294967295,n.lowOrder>>>e|n.highOrder<<32-e&4294967295):new w(n.lowOrder>>>e-32|n.highOrder<<64-e&4294967295,n.highOrder>>>e-32|n.lowOrder<<64-e&4294967295)}function A(r,e){return r>>>e}function S(r,e){return 32>=e?new w(r.highOrder>>>e,r.lowOrder>>>e|r.highOrder<<32-e&4294967295):new w(0,r.highOrder>>>e-32)}function E(r,e,n){return r^e^n}function p(r,e,n){return r&e^~r&n}function H(r,e,n){return new w(r.highOrder&e.highOrder^~r.highOrder&n.highOrder,r.lowOrder&e.lowOrder^~r.lowOrder&n.lowOrder)}function v(r,e,n){return r&e^r&n^e&n}function P(r,e,n){return new w(r.highOrder&e.highOrder^r.highOrder&n.highOrder^e.highOrder&n.highOrder,r.lowOrder&e.lowOrder^r.lowOrder&n.lowOrder^e.lowOrder&n.lowOrder)}function U(r){return c(r,2)^c(r,13)^c(r,22)}function b(r){var e=g(r,28),n=g(r,34),t=g(r,39);return new w(e.highOrder^n.highOrder^t.highOrder,e.lowOrder^n.lowOrder^t.lowOrder)}function R(r){return c(r,6)^c(r,11)^c(r,25)}function T(r){var e=g(r,14),n=g(r,18),t=g(r,41);return new w(e.highOrder^n.highOrder^t.highOrder,e.lowOrder^n.lowOrder^t.lowOrder)}function L(r){return c(r,7)^c(r,18)^A(r,3)}function m(r){var e=g(r,1),n=g(r,8),t=S(r,7);return new w(e.highOrder^n.highOrder^t.highOrder,e.lowOrder^n.lowOrder^t.lowOrder)}function y(r){return c(r,17)^c(r,19)^A(r,10)}function F(r){var e=g(r,19),n=g(r,61),t=S(r,6);return new w(e.highOrder^n.highOrder^t.highOrder,e.lowOrder^n.lowOrder^t.lowOrder)}function k(r,e){var n=(65535&r)+(65535&e);return(65535&(r>>>16)+(e>>>16)+(n>>>16))<<16|65535&n}function B(r,e,n,t){var o=(65535&r)+(65535&e)+(65535&n)+(65535&t);return(65535&(r>>>16)+(e>>>16)+(n>>>16)+(t>>>16)+(o>>>16))<<16|65535&o}function D(r,e,n,t,o){var i=(65535&r)+(65535&e)+(65535&n)+(65535&t)+(65535&o);return(65535&(r>>>16)+(e>>>16)+(n>>>16)+(t>>>16)+(o>>>16)+(i>>>16))<<16|65535&i}function G(r,e){var n,t,o;return n=(65535&r.lowOrder)+(65535&e.lowOrder),o=(65535&(t=(r.lowOrder>>>16)+(e.lowOrder>>>16)+(n>>>16)))<<16|65535&n,n=(65535&r.highOrder)+(65535&e.highOrder)+(t>>>16),new w((65535&(t=(r.highOrder>>>16)+(e.highOrder>>>16)+(n>>>16)))<<16|65535&n,o)}function C(r,e,n,t){var o,i,h;return o=(65535&r.lowOrder)+(65535&e.lowOrder)+(65535&n.lowOrder)+(65535&t.lowOrder),h=(65535&(i=(r.lowOrder>>>16)+(e.lowOrder>>>16)+(n.lowOrder>>>16)+(t.lowOrder>>>16)+(o>>>16)))<<16|65535&o,o=(65535&r.highOrder)+(65535&e.highOrder)+(65535&n.highOrder)+(65535&t.highOrder)+(i>>>16),new w((65535&(i=(r.highOrder>>>16)+(e.highOrder>>>16)+(n.highOrder>>>16)+(t.highOrder>>>16)+(o>>>16)))<<16|65535&o,h)}function _(r,e,n,t,o){var i,h,u;return i=(65535&r.lowOrder)+(65535&e.lowOrder)+(65535&n.lowOrder)+(65535&t.lowOrder)+(65535&o.lowOrder),u=(65535&(h=(r.lowOrder>>>16)+(e.lowOrder>>>16)+(n.lowOrder>>>16)+(t.lowOrder>>>16)+(o.lowOrder>>>16)+(i>>>16)))<<16|65535&i,i=(65535&r.highOrder)+(65535&e.highOrder)+(65535&n.highOrder)+(65535&t.highOrder)+(65535&o.highOrder)+(h>>>16),new w((65535&(h=(r.highOrder>>>16)+(e.highOrder>>>16)+(n.highOrder>>>16)+(t.highOrder>>>16)+(o.highOrder>>>16)+(i>>>16)))<<16|65535&i,u)}function x(r,e){return new w(r.highOrder^e.highOrder,r.lowOrder^e.lowOrder)}function X(r){var e,n,t,o=[];if("SHA-1"===r&&0!=(1&SUPPORTED_ALGS))o=[1732584193,4023233417,2562383102,271733878,3285377520];else if(0===r.lastIndexOf("SHA-",0)&&0!=(6&SUPPORTED_ALGS))switch(e=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428],n=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],r){case"SHA-224":o=e;break;case"SHA-256":o=n;break;case"SHA-384":o=[new w(3418070365,e[0]),new w(1654270250,e[1]),new w(2438529370,e[2]),new w(355462360,e[3]),new w(1731405415,e[4]),new w(41048885895,e[5]),new w(3675008525,e[6]),new w(1203062813,e[7])];break;case"SHA-512":o=[new w(n[0],4089235720),new w(n[1],2227873595),new w(n[2],4271175723),new w(n[3],1595750129),new w(n[4],2917565137),new w(n[5],725511199),new w(n[6],4215389547),new w(n[7],327033209)];break;default:throw new Error("Unknown SHA variant")}else{if(0!==r.lastIndexOf("SHA3-",0)&&0!==r.lastIndexOf("SHAKE",0)||0==(8&SUPPORTED_ALGS))throw new Error("No SHA variants supported");for(t=0;t<5;t+=1)o[t]=[new w(0,0),new w(0,0),new w(0,0),new w(0,0),new w(0,0)]}return o}function Y(r,e){var n,t,o,i,w,h,u,d=[],f=p,a=E,O=v,s=l,c=k,g=D;for(n=e[0],t=e[1],o=e[2],i=e[3],w=e[4],u=0;u<80;u+=1)d[u]=u<16?r[u]:s(d[u-3]^d[u-8]^d[u-14]^d[u-16],1),h=u<20?g(s(n,5),f(t,o,i),w,1518500249,d[u]):u<40?g(s(n,5),a(t,o,i),w,1859775393,d[u]):u<60?g(s(n,5),O(t,o,i),w,2400959708,d[u]):g(s(n,5),a(t,o,i),w,3395469782,d[u]),w=i,i=o,o=s(t,30),t=n,n=h;return e[0]=c(n,e[0]),e[1]=c(t,e[1]),e[2]=c(o,e[2]),e[3]=c(i,e[3]),e[4]=c(w,e[4]),e}function I(r,e,n,t,o){var w,h,u,d;for(u=15+(e+65>>>9<<4);r.length<=u;)r.push(0);for(r[e>>>5]|=128<<24-e%32,d=e+n,r[u]=4294967295&d,r[u-1]=d/i|0,h=r.length,w=0;w<h;w+=16)t=Y(r.slice(w,w+16),t);return t}function M(r,t,o){var i,h,u,d,f,a,O,l,s,c,g,A,S,E,x,X,Y,I,M,K,N,j,Z,z,J,Q,V,W=[];if("SHA-224"!==o&&"SHA-256"!==o||0==(2&SUPPORTED_ALGS)){if("SHA-384"!==o&&"SHA-512"!==o||0==(4&SUPPORTED_ALGS))throw new Error("Unexpected error in SHA-2 implementation");g=80,S=2,Z=w,E=G,x=C,X=_,Y=m,I=F,M=b,K=T,j=P,N=H,V=n}else g=64,S=1,Z=Number,E=k,x=B,X=D,Y=L,I=y,M=U,K=R,j=v,N=p,V=e;for(i=t[0],h=t[1],u=t[2],d=t[3],f=t[4],a=t[5],O=t[6],l=t[7],A=0;A<g;A+=1)A<16?(Q=A*S,z=r.length<=Q?0:r[Q],J=r.length<=Q+1?0:r[Q+1],W[A]=new Z(z,J)):W[A]=x(I(W[A-2]),W[A-7],Y(W[A-15]),W[A-16]),s=X(l,K(f),N(f,a,O),V[A],W[A]),c=E(M(i),j(i,h,u)),l=O,O=a,a=f,f=E(d,s),d=u,u=h,h=i,i=E(s,c);return t[0]=E(i,t[0]),t[1]=E(h,t[1]),t[2]=E(u,t[2]),t[3]=E(d,t[3]),t[4]=E(f,t[4]),t[5]=E(a,t[5]),t[6]=E(O,t[6]),t[7]=E(l,t[7]),t}function K(r,e){var n,i,h,u,d,f,a,O,l,c=[],g=[];if(null!==r)for(i=0;i<r.length;i+=2)e[(i>>>1)%5][(i>>>1)/5|0]=x(e[(i>>>1)%5][(i>>>1)/5|0],new w(r[i+1],r[i]));for(n=0;n<24;n+=1){for(u=X("SHA3-"),i=0;i<5;i+=1)c[i]=(d=e[i][0],f=e[i][1],a=e[i][2],O=e[i][3],l=e[i][4],new w(d.highOrder^f.highOrder^a.highOrder^O.highOrder^l.highOrder,d.lowOrder^f.lowOrder^a.lowOrder^O.lowOrder^l.lowOrder));for(i=0;i<5;i+=1)g[i]=x(c[(i+4)%5],s(c[(i+1)%5],1));for(i=0;i<5;i+=1)for(h=0;h<5;h+=1)e[i][h]=x(e[i][h],g[i]);for(i=0;i<5;i+=1)for(h=0;h<5;h+=1)u[h][(2*i+3*h)%5]=s(e[i][h],t[i][h]);for(i=0;i<5;i+=1)for(h=0;h<5;h+=1)e[i][h]=x(u[i][h],new w(~u[(i+1)%5][h].highOrder&u[(i+2)%5][h].highOrder,~u[(i+1)%5][h].lowOrder&u[(i+2)%5][h].lowOrder));e[0][0]=x(e[0][0],o[n])}return e}0!=(6&SUPPORTED_ALGS)&&(e=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],0!=(4&SUPPORTED_ALGS)&&(n=[new w(e[0],3609767458),new w(e[1],602891725),new w(e[2],3964484399),new w(e[3],2173295548),new w(e[4],4081628472),new w(e[5],3053834265),new w(e[6],2937671579),new w(e[7],3664609560),new w(e[8],2734883394),new w(e[9],1164996542),new w(e[10],1323610764),new w(e[11],3590304994),new w(e[12],4068182383),new w(e[13],991336113),new w(e[14],633803317),new w(e[15],3479774868),new w(e[16],2666613458),new w(e[17],944711139),new w(e[18],2341262773),new w(e[19],2007800933),new w(e[20],1495990901),new w(e[21],1856431235),new w(e[22],3175218132),new w(e[23],2198950837),new w(e[24],3999719339),new w(e[25],766784016),new w(e[26],2566594879),new w(e[27],3203337956),new w(e[28],1034457026),new w(e[29],2466948901),new w(e[30],3758326383),new w(e[31],168717936),new w(e[32],1188179964),new w(e[33],1546045734),new w(e[34],1522805485),new w(e[35],2643833823),new w(e[36],2343527390),new w(e[37],1014477480),new w(e[38],1206759142),new w(e[39],344077627),new w(e[40],1290863460),new w(e[41],3158454273),new w(e[42],3505952657),new w(e[43],106217008),new w(e[44],3606008344),new w(e[45],1432725776),new w(e[46],1467031594),new w(e[47],851169720),new w(e[48],3100823752),new w(e[49],1363258195),new w(e[50],3750685593),new w(e[51],3785050280),new w(e[52],3318307427),new w(e[53],3812723403),new w(e[54],2003034995),new w(e[55],3602036899),new w(e[56],1575990012),new w(e[57],1125592928),new w(e[58],2716904306),new w(e[59],442776044),new w(e[60],593698344),new w(e[61],3733110249),new w(e[62],2999351573),new w(e[63],3815920427),new w(3391569614,3928383900),new w(3515267271,566280711),new w(3940187606,3454069534),new w(4118630271,4000239992),new w(116418474,1914138554),new w(174292421,2731055270),new w(289380356,3203993006),new w(460393269,320620315),new w(685471733,587496836),new w(852142971,1086792851),new w(1017036298,365543100),new w(1126000580,2618297676),new w(1288033470,3409855158),new w(1501505948,4234509866),new w(1607167915,987167468),new w(1816402316,1246189591)])),0!=(8&SUPPORTED_ALGS)&&(o=[new w(0,1),new w(0,32898),new w(2147483648,32906),new w(2147483648,2147516416),new w(0,32907),new w(0,2147483649),new w(2147483648,2147516545),new w(2147483648,32777),new w(0,138),new w(0,136),new w(0,2147516425),new w(0,2147483658),new w(0,2147516555),new w(2147483648,139),new w(2147483648,32905),new w(2147483648,32771),new w(2147483648,32770),new w(2147483648,128),new w(0,32778),new w(2147483648,2147483658),new w(2147483648,2147516545),new w(2147483648,32896),new w(0,2147483649),new w(2147483648,2147516424)],t=[[0,36,3,41,18],[1,44,10,45,2],[62,6,43,15,61],[28,55,25,21,56],[27,20,39,8,14]]);var N=function(r,e,n){var t,o,w,l,s,c,g,A,S,E,p=0,H=[],v=0,P=r,U=!1,b=[],R=[],T=!1,L=!1,m=-1;if(t=(E=n||{}).encoding||"UTF8",(S=E.numRounds||1)!==parseInt(S,10)||1>S)throw new Error("numRounds must a integer >= 1");if("SHA-1"===P&&0!=(1&SUPPORTED_ALGS))s=512,c=Y,g=I,l=160,A=function(r){return r.slice()};else if(0===P.lastIndexOf("SHA-",0)&&0!=(6&SUPPORTED_ALGS))if(c=function(r,e){return M(r,e,P)},g=function(r,e,n,t,o){return function(r,e,n,t,o,w){var h,u,d,f,a,O;if("SHA-224"!==o&&"SHA-256"!==o||0==(2&SUPPORTED_ALGS)){if("SHA-384"!==o&&"SHA-512"!==o||0==(4&SUPPORTED_ALGS))throw new Error("Unexpected error in SHA-2 implementation");d=31+(e+129>>>10<<5),a=32}else d=15+(e+65>>>9<<4),a=16;for(;r.length<=d;)r.push(0);for(r[e>>>5]|=128<<24-e%32,O=e+n,r[d]=4294967295&O,r[d-1]=O/i|0,u=r.length,h=0;h<u;h+=a)t=M(r.slice(h,h+a),t,o);if("SHA-224"===o&&0!=(2&SUPPORTED_ALGS))f=[t[0],t[1],t[2],t[3],t[4],t[5],t[6]];else if("SHA-256"===o&&0!=(2&SUPPORTED_ALGS))f=t;else if("SHA-384"===o&&0!=(4&SUPPORTED_ALGS))f=[t[0].highOrder,t[0].lowOrder,t[1].highOrder,t[1].lowOrder,t[2].highOrder,t[2].lowOrder,t[3].highOrder,t[3].lowOrder,t[4].highOrder,t[4].lowOrder,t[5].highOrder,t[5].lowOrder];else{if("SHA-512"!==o||0==(4&SUPPORTED_ALGS))throw new Error("Unexpected error in SHA-2 implementation");f=[t[0].highOrder,t[0].lowOrder,t[1].highOrder,t[1].lowOrder,t[2].highOrder,t[2].lowOrder,t[3].highOrder,t[3].lowOrder,t[4].highOrder,t[4].lowOrder,t[5].highOrder,t[5].lowOrder,t[6].highOrder,t[6].lowOrder,t[7].highOrder,t[7].lowOrder]}return f}(r,e,n,t,P)},A=function(r){return r.slice()},"SHA-224"===P&&0!=(2&SUPPORTED_ALGS))s=512,l=224;else if("SHA-256"===P&&0!=(2&SUPPORTED_ALGS))s=512,l=256;else if("SHA-384"===P&&0!=(4&SUPPORTED_ALGS))s=1024,l=384;else{if("SHA-512"!==P||0==(4&SUPPORTED_ALGS))throw new Error("Chosen SHA variant is not supported "+P);s=1024,l=512}else{if(0!==P.lastIndexOf("SHA3-",0)&&0!==P.lastIndexOf("SHAKE",0)||0==(8&SUPPORTED_ALGS))throw new Error("Chosen SHA varwwwiant is not supported "+P);var y=6;if(c=K,A=function(r){return function(r){var e,n=[];for(e=0;e<5;e+=1)n[e]=r[e].slice();return n}(r)},m=1,"SHA3-224"===P)s=1152,l=224;else if("SHA3-256"===P)s=1088,l=256;else if("SHA3-384"===P)s=832,l=384;else if("SHA3-512"===P)s=576,l=512;else if("SHAKE128"===P)s=1344,l=-1,y=31,L=!0;else{if("SHAKE256"!==P)throw new Error("Chosen SHA variant is not supported "+P);s=1088,l=-1,y=31,L=!0}g=function(r,e,n,t,o){return function(r,e,n,t,o,i,w){var h,u,d=[],f=o>>>5,a=0,O=e>>>5;for(h=0;h<O&&e>=o;h+=f)t=K(r.slice(h,h+f),t),e-=o;for(r=r.slice(h),e%=o;r.length<f;)r.push(0);for(r[(h=e>>>3)>>2]^=i<<h%4*8,r[f-1]^=2147483648,t=K(r,t);32*d.length<w&&(u=t[a%5][a/5|0],d.push(u.lowOrder),!(32*d.length>=w));)d.push(u.highOrder),0==64*(a+=1)%o&&K(null,t);return d}(r,e,0,t,s,y,o)}}w=O(e,t,m),o=X(P),this.setHMACKey=function(r,e,n){var i,w,h,u,d,f;if(!0===U)throw new Error("HMAC key already set");if(!0===T)throw new Error("Cannot set HMAC key after calling update");if(!0===L&&0!=(8&SUPPORTED_ALGS))throw new Error("SHAKE is not supported for HMAC");if(w=(i=O(e,t=(n||{}).encoding||"UTF8",m)(r)).binLen,h=i.value,f=(u=s>>>3)/4-1,u<w/8){for(h=g(h,w,0,X(P),l);h.length<=f;)h.push(0);h[f]&=4294967040}else if(u>w/8){for(;h.length<=f;)h.push(0);h[f]&=4294967040}for(d=0;d<=f;d+=1)b[d]=909522486^h[d],R[d]=1549556828^h[d];o=c(b,o),p=s,U=!0},this.update=function(r){var e,n,t,i,h,u=0,d=s>>>5;for(n=(e=w(r,H,v)).binLen,i=e.value,t=n>>>5,h=0;h<t;h+=d)u+s<=n&&(o=c(i.slice(h,h+d),o),u+=s);p+=u,H=i.slice(u>>>5),v=n%s,T=!0},this.getHash=function(r,e){var n,t,i,w;if(!0===U)throw new Error("Cannot call getHash after setting HMAC key");if(i=a(e),!0===L&&0!=(8&SUPPORTED_ALGS)){if(-1===i.shakeLen)throw new Error("shakeLen must be specified in options");l=i.shakeLen}switch(r){case"HEX":n=function(r){return h(r,l,m,i)};break;case"B64":n=function(r){return u(r,l,m,i)};break;case"BYTES":n=function(r){return d(r,l,m)};break;case"ARRAYBUFFER":try{t=new ArrayBuffer(0)}catch(r){throw new Error("ARRAYBUFFER not supported by this environment")}n=function(r){return f(r,l,m)};break;default:throw new Error("format must be HEX, B64, BYTES, or ARRAYBUFFER")}for(w=g(H.slice(),v,p,A(o),l),t=1;t<S;t+=1)0!=(8&SUPPORTED_ALGS)&&!0===L&&l%32!=0&&(w[w.length-1]&=16777215>>>24-l%32),w=g(w,l,0,X(P),l);return n(w)},this.getHMAC=function(r,e){var n,t,i,w;if(!1===U)throw new Error("Cannot call getHMAC without first setting HMAC key");switch(i=a(e),r){case"HEX":n=function(r){return h(r,l,m,i)};break;case"B64":n=function(r){return u(r,l,m,i)};break;case"BYTES":n=function(r){return d(r,l,m)};break;case"ARRAYBUFFER":try{n=new ArrayBuffer(0)}catch(r){throw new Error("ARRAYBUFFER not supported by this environment")}n=function(r){return f(r,l,m)};break;default:throw new Error("outputFormat must be HEX, B64, BYTES, or ARRAYBUFFER")}return t=g(H.slice(),v,p,A(o),l),w=c(R,X(P)),n(w=g(t,l,s,w,l))}};"function"==typeof define&&define.amd?define(function(){return N}):"undefined"!=typeof exports?"undefined"!=typeof module&&module.exports?(module.exports=N,exports=N):exports=N:r.jsSHA=N}(X),TOTP=function(){var r=function(r){return parseInt(r,16)},e=function(r,e,n){return e+1>=r.length&&(r=Array(e+1-r.length).join(n)+r),r};this.getOTP=function(n){try{var t=function(r){for(var n="",t="",o=0;o<r.length;o++){var i="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567".indexOf(r.charAt(o).toUpperCase());n+=e(i.toString(2),5,"0")}for(o=0;o+4<=n.length;o+=4){var w=n.substr(o,4);t+=parseInt(w,2).toString(16)}return t}(n),o=Math.round((new Date).getTime()/1e3),i=e(((f=Math.floor(o/30))<15.5?"0":"")+Math.round(f).toString(16),16,"0"),w=new X.jsSHA("SHA-1","HEX");w.setHMACKey(t,"HEX"),w.update(i);var h=w.getHMAC("HEX"),u=r(h.substring(h.length-1)),d=(r(h.substr(2*u,8))&r("7fffffff"))+"";d=d.substr(d.length-6,6)}catch(r){throw r}var f;return d}};