From 7747ec8a9ef7d18a67af3c0adc7bbeaf0a4dd461 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Fri, 29 Oct 2021 21:37:38 +0800 Subject: [PATCH 001/132] Create app.js --- apps/authentiwatch/app.js | 263 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 263 insertions(+) create mode 100644 apps/authentiwatch/app.js diff --git a/apps/authentiwatch/app.js b/apps/authentiwatch/app.js new file mode 100644 index 000000000..19c54a175 --- /dev/null +++ b/apps/authentiwatch/app.js @@ -0,0 +1,263 @@ +const tokenentryheight = 46; +// Hash functions +const crypto = require("crypto"); +const sha1 = crypto.SHA1; +const sha224 = crypto.SHA224; +const sha256 = crypto.SHA256; +const sha384 = crypto.SHA384; +const sha512 = crypto.SHA512; + +var tokens = require("Storage").readJSON("authentiwatch.tokens.json", true) || [ + {algorithm:"SHA512",digits:8,period:60,secret:"aaaa aaaa aaaa aaaa",label:"AgAgAg"}, + {algorithm:"SHA1",digits:6,period:30,secret:"bbbb bbbb bbbb bbbb",label:"BgBgBg"}, + {algorithm:"SHA1",digits:6,period:30,secret:"6crw upgx ntjb 3wuj",label:"Discord"}, + {algorithm:"SHA1",digits:6,period:60,secret:"yyyy yyyy yyyy yyyy",label:"YgYgYg"}, + {algorithm:"SHA1",digits:8,period:30,secret:"zzzz zzzz zzzz zzzz",label:"ZgZgZg"}, +]; + +// QR Code Text +// +// Example: +// +// otpauth://totp/${url}:AA_${algorithm}_${digits}dig_${period}s@${url}?algorithm=${algorithm}&digits=${digits}&issuer=${url}&period=${period}&secret=${secret} +// +// ${algorithm} : one of SHA1 / SHA256 / SHA512 +// ${digits} : one of 6 / 8 +// ${period} : one of 30 / 60 +// ${url} : a domain name "example.com" +// ${secret} : the seed code + +function b32decode(seedstr) { + // RFC4648 + var i, buf = 0, bitcount = 0, retstr = ""; + for (i in seedstr) { + let c = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567".indexOf(seedstr.charAt(i).toUpperCase(), 0); + if (c != -1) { + buf <<= 5; + buf |= c; + bitcount += 5; + if (bitcount >= 8) { + retstr += String.fromCharCode(buf >> (bitcount - 8)); + buf &= (0xFF >> (16 - bitcount)); + bitcount -= 8; + } + } + } + if (bitcount > 0) { + retstr += String.fromCharCode(buf << (8 - bitcount)); + } + var retbuf = new Uint8Array(retstr.length); + for (i in retstr) { + retbuf[i] = retstr.charCodeAt(i); + } + return retbuf; +} +function do_hmac(key, message, algo) { + var sha, retsz, blksz; + if (algo == "SHA512") { + sha = sha512; + retsz = 64; + blksz = 128; + } else if (algo == "SHA384") { + sha = sha384; + retsz = 48; + blksz = 128; + } else if (algo == "SHA256") { + sha = sha256; + retsz = 32; + blksz = 64; + } else if (algo == "SHA224") { + sha = sha224; + retsz = 28; + blksz = 64; + } else { + sha = sha1; + retsz = 20; + blksz = 64; + } + // RFC2104 + if (key.length > blksz) { + key = sha(key); + } + var istr = new Uint8Array(blksz + message.length); + var ostr = new Uint8Array(blksz + retsz); + for (var i = 0; i < blksz; ++i) { + let c = (i < key.length) ? key[i] : 0; + istr[i] = c ^ 0x36; + ostr[i] = c ^ 0x5C; + } + istr.set(message, blksz); + ostr.set(sha(istr), blksz); + var ret = sha(ostr); + // RFC4226 dynamic truncation + var v = new DataView(ret, ret[ret.length - 1] & 0x0F, 4); + return v.getUint32(0) & 0x7FFFFFFF; +} +function hotp_timed(seed, digits, period, algo) { + // RFC6238 + var d = new Date(); + var seconds = Math.floor(d.getTime() / 1000); + var tick = Math.floor(seconds / period); + var msg = new Uint8Array(8); + var v = new DataView(msg.buffer); + v.setUint32(0, tick >> 16 >> 16); + v.setUint32(4, tick & 0xFFFFFFFF); + var hash = do_hmac(b32decode(seed), msg, algo.toUpperCase()); + var ret = "" + hash % Math.pow(10, digits); + while (ret.length < digits) { + ret = "0" + ret; + } + return {hotp:ret, next:(tick + 1) * period * 1000}; +} + +var state = { + listy: 0, + curtoken:-1, + nextTime:0, + otp:"", + rem:0 +}; + +function drawToken(id, r) { + var x1 = r.x; + var y1 = r.y; + var x2 = r.x + r.w - 1; + var y2 = r.y + r.h - 1; + var ylabel; + if (id == state.curtoken) { + // current token + g.setColor(g.theme.fgH); + g.setBgColor(g.theme.bgH); + g.setFont6x15(1); + // center just below top line + g.setFontAlign(0, -1, 0); + ylabel = y1 + 2; + } else { + g.setColor(g.theme.fg); + g.setBgColor(g.theme.bg); + g.setFont6x15(2); + // center in box + g.setFontAlign(0, 0, 0); + ylabel = (y1 + y2) / 2; + } + g.clearRect(x1, y1, x2, y2); + g.drawString(tokens[id].label, x2 / 2, ylabel, false); + if (id == state.curtoken) { + // digits just below label + g.setFont6x15(2); + g.drawString(state.otp, x2 / 2, y1 + 17, false); + // draw progress bar + let xr = Math.floor(g.getWidth() * state.rem / tokens[id].period); + g.fillRect(x1, y2 - 4, xr, y2 - 1); + } + // shaded lines top and bottom + if (g.theme.dark) { + g.setColor(0.25, 0.25, 0.25); + } else { + g.setColor(0.75, 0.75, 0.75); + } + g.drawLine(x1, y1, x2, y1); + g.drawLine(x1, y2, x2, y2); +} + +function draw() { + if (state.curtoken != -1) { + var t = tokens[state.curtoken]; + var d = new Date(); + if (d.getTime() > state.nextTime) { + try { + var r = hotp_timed(t.secret, t.digits, t.period, t.algorithm); + state.nextTime = r.next; + state.otp = r.hotp; + } catch (err) { + state.nextTime = 0; + state.otp = "Not supported"; + } + } + state.rem = Math.max(0, Math.floor((state.nextTime - d.getTime()) / 1000)); + } + if (tokens.length > 0) { + var drewcur = false; + var id = Math.floor(state.listy / tokenentryheight); + var y = id * tokenentryheight - state.listy; + while (id < tokens.length && y < g.getHeight()) { + drawToken(id, {x:0, y:y, w:g.getWidth(), h:tokenentryheight}); + if (id == state.curtoken && state.nextTime != 0) { + drewcur = true; + } + id += 1; + y += tokenentryheight; + } + if (drewcur) { + if (state.drawtimer) { + clearTimeout(state.drawtimer); + } + state.drawtimer = setTimeout(draw, 1000); + } + } else { + g.setFont6x15(2); + g.setFontAlign(0, 0, 0); + g.drawString("No tokens", g.getWidth() / 2, g.getHeight() / 2, false); + } +} + +function onTouch(zone, e) { + var id = Math.floor((state.listy + e.y) / tokenentryheight); + if (id == state.curtoken) { + id = -1; + } + if (state.curtoken != id) { + if (id != -1) { + var y = id * tokenentryheight - state.listy; + if (y < 0) { + state.listy += y; + y = 0; + } + y += tokenentryheight; + if (y > g.getHeight()) { + state.listy += (y - g.getHeight()); + } + } + state.nextTime = 0; + state.curtoken = id; + draw(); + } +} + +function onDrag(e) { + if (e.x > g.getWidth() || e.y > g.getHeight()) return; + if (e.dx == 0 && e.dy == 0) return; + var maxy = tokens.length * tokenentryheight - g.getHeight(); + var newy = state.listy - e.dy; + if (newy > maxy) { + newy = maxy; + } + if (newy < 0) { + newy = 0; + } + if (newy != state.listy) { + state.listy = newy; + draw(); + } +} + +function onSwipe(e) { + if (e == 1) { + Bangle.showLauncher(); + } +} + +function tokenSelected(id) { + state.curtoken = (id == state.curtoken) ? -1 : id; + scroller.drawMenu(); +} + +Bangle.on('touch', onTouch); +Bangle.on('drag' , onDrag ); +Bangle.on('swipe', onSwipe); + +// Clear the screen once, at startup +g.clear(); +draw(); + +//var scroller = E.showScroller({h:tokenentryheight,c:tokens.length,draw:drawToken,select:tokenSelected}); From d2fd5af3e6741e811c66279b47ca74d1c9a79361 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Fri, 29 Oct 2021 21:41:01 +0800 Subject: [PATCH 002/132] Create app-icon.js --- apps/authentiwatch/app-icon.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 apps/authentiwatch/app-icon.js diff --git a/apps/authentiwatch/app-icon.js b/apps/authentiwatch/app-icon.js new file mode 100644 index 000000000..27ced695e --- /dev/null +++ b/apps/authentiwatch/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mUywkBiIADCxoTFAAcQGBwY/DDQIKDBiMDDCgGCBI4YMGAIDFDCAFEBQwYLFgIYEGQgYMApoYJGAJjFMogYMSQgCDDBwDCY4oMEDBZgHHQQYQf4oYVBgwYQBogYPPYZpFDBKMEDAbdDCxT9IDYIFFABqSEAogySQYoWNFgrFDJZoQBJggYRBwhLGDBwyFDCZGEDCYAEDGrIMbwhnGDEpLGAwxlLFQgQDJiYoFDDAZDDCpMDMpQOCNxQYNBo4KKBpwYYBYJ8NeJgYkLBQY8UYQXVGQIwN")) From e60f6447a5db602a8dcacb5bf481baffa0527852 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Fri, 29 Oct 2021 21:46:35 +0800 Subject: [PATCH 003/132] Add authentiwatch --- apps.json | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/apps.json b/apps.json index edc70c8ee..ca0919db4 100644 --- a/apps.json +++ b/apps.json @@ -4183,5 +4183,18 @@ { "name": "qalarm.wid.js", "url": "widget.js" } ], "data": [{ "name": "qalarm.json" }] + }, + { + "id": "authentiwatch", + "name": "2FA Authenticator", + "shortName": "AuthWatch", + "icon": "app.png", + "version": "0.01", + "description": "Google Authenticator compatible tool.", + "tags": "", + "storage": [ + {"name":"authentiwatch.app.js","url":"authentiwatch.js"}, + {"name":"authentiwatch.img","url":"app-icon.js","evaluate":true} + ] } ] From 2cbb0b46854f95ddfcae0fe949e069269e7af8ca Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Fri, 29 Oct 2021 21:50:54 +0800 Subject: [PATCH 004/132] Update apps.json --- apps.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps.json b/apps.json index ca0919db4..476be59c8 100644 --- a/apps.json +++ b/apps.json @@ -4193,7 +4193,7 @@ "description": "Google Authenticator compatible tool.", "tags": "", "storage": [ - {"name":"authentiwatch.app.js","url":"authentiwatch.js"}, + {"name":"authentiwatch.app.js","url":"app.js"}, {"name":"authentiwatch.img","url":"app-icon.js","evaluate":true} ] } From 38559fce4ea0329299426187fcfebd65e8ef5f90 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Fri, 29 Oct 2021 21:52:06 +0800 Subject: [PATCH 005/132] Update apps.json --- apps.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps.json b/apps.json index 476be59c8..12b8a658b 100644 --- a/apps.json +++ b/apps.json @@ -4191,7 +4191,8 @@ "icon": "app.png", "version": "0.01", "description": "Google Authenticator compatible tool.", - "tags": "", + "tags": "tool", + "supports": ["BANGLEJS","BANGLEJS2"], "storage": [ {"name":"authentiwatch.app.js","url":"app.js"}, {"name":"authentiwatch.img","url":"app-icon.js","evaluate":true} From c7232538cf87003b3e8eccf9c85cb438fe8e4efc Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Fri, 29 Oct 2021 21:56:16 +0800 Subject: [PATCH 006/132] Add files via upload --- apps/authentiwatch/app.png | Bin 0 -> 964 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 apps/authentiwatch/app.png diff --git a/apps/authentiwatch/app.png b/apps/authentiwatch/app.png new file mode 100644 index 0000000000000000000000000000000000000000..208fb63b348a960529406347f23aa9363271a388 GIT binary patch literal 964 zcmV;#13UbQP)xsf51t(*UgawVs8_EtK4Uj6!KPV)p)DWINn^zpuWJITwM`Wz=ZH; z2ril046 z3E3dFLQDKf@v|{0A?0HG9WmfPz)j#7(15DJ(x^HNV2#FC>_Rq)?OOy9_fSi2F4O^c zh*3yb`s@?i1G#?*97nz3G*AI-1NQs;>;U?JQQ$A|3-|SWjpa|Gb^Y>RlRNsji4&tdEh;84fQ2lbO2fOf*u2FEycbB zt*D*a^tSta0d^R;4l32GB87MU=)x?Tc_ z^|h?vqb7i@K2EKMGa~i|jokr$#;!mxrwQO8N=z+k{)BPdlVXL&?f@Sw>EMSUh+J(! ze54JWo_vBSF(P9Z=2FA7*|{al?Ff7; zxRIv_|3+7jI-`_?kQCuZU0r)BeL$5c3#irU3TkgL^^HBv)}h|ADb2E|(j=wv;iB8% z!-^PCd9Mqg$~WT0 Date: Fri, 29 Oct 2021 22:01:23 +0800 Subject: [PATCH 007/132] Update apps.json --- apps.json | 1 + 1 file changed, 1 insertion(+) diff --git a/apps.json b/apps.json index 12b8a658b..146608bdc 100644 --- a/apps.json +++ b/apps.json @@ -4193,6 +4193,7 @@ "description": "Google Authenticator compatible tool.", "tags": "tool", "supports": ["BANGLEJS","BANGLEJS2"], + "allow_emulator": true, "storage": [ {"name":"authentiwatch.app.js","url":"app.js"}, {"name":"authentiwatch.img","url":"app-icon.js","evaluate":true} From 3235c642bd90a673f1e18d638acb02c9eae89569 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Fri, 29 Oct 2021 22:05:16 +0800 Subject: [PATCH 008/132] Update apps.json --- apps.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps.json b/apps.json index 146608bdc..bcea14b1d 100644 --- a/apps.json +++ b/apps.json @@ -4197,6 +4197,7 @@ "storage": [ {"name":"authentiwatch.app.js","url":"app.js"}, {"name":"authentiwatch.img","url":"app-icon.js","evaluate":true} - ] + ], + "data": [{"name":"authentiwatch.json"}] } ] From 9b2d8f8cc42cb777aa96fa9c75efcaac7b34c105 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Fri, 29 Oct 2021 22:10:43 +0800 Subject: [PATCH 009/132] Update app.js --- apps/authentiwatch/app.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/authentiwatch/app.js b/apps/authentiwatch/app.js index 19c54a175..d0d951e99 100644 --- a/apps/authentiwatch/app.js +++ b/apps/authentiwatch/app.js @@ -10,7 +10,8 @@ const sha512 = crypto.SHA512; var tokens = require("Storage").readJSON("authentiwatch.tokens.json", true) || [ {algorithm:"SHA512",digits:8,period:60,secret:"aaaa aaaa aaaa aaaa",label:"AgAgAg"}, {algorithm:"SHA1",digits:6,period:30,secret:"bbbb bbbb bbbb bbbb",label:"BgBgBg"}, - {algorithm:"SHA1",digits:6,period:30,secret:"6crw upgx ntjb 3wuj",label:"Discord"}, + {algorithm:"SHA1",digits:6,period:30,secret:"cccc cccc cccc cccc",label:"CgCgCg"}, + {algorithm:"SHA1",digits:6,period:30,secret:"xxxx xxxx xxxx xxxx",label:"XgXgXg"}, {algorithm:"SHA1",digits:6,period:60,secret:"yyyy yyyy yyyy yyyy",label:"YgYgYg"}, {algorithm:"SHA1",digits:8,period:30,secret:"zzzz zzzz zzzz zzzz",label:"ZgZgZg"}, ]; From 654e0b1e38246286e4d3d665eb98f1cfdea7f413 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Fri, 29 Oct 2021 22:25:26 +0800 Subject: [PATCH 010/132] Update apps.json --- apps.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps.json b/apps.json index bcea14b1d..cba05c73a 100644 --- a/apps.json +++ b/apps.json @@ -4198,6 +4198,6 @@ {"name":"authentiwatch.app.js","url":"app.js"}, {"name":"authentiwatch.img","url":"app-icon.js","evaluate":true} ], - "data": [{"name":"authentiwatch.json"}] + "data": [{"name":"authentiwatch.tokens.json"}] } ] From 9b5bda19c557b052da0a2b7e1e567dc4d4bdc873 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Fri, 29 Oct 2021 22:27:14 +0800 Subject: [PATCH 011/132] Update apps.json --- apps.json | 1 + 1 file changed, 1 insertion(+) diff --git a/apps.json b/apps.json index cba05c73a..5c9ac4889 100644 --- a/apps.json +++ b/apps.json @@ -4192,6 +4192,7 @@ "version": "0.01", "description": "Google Authenticator compatible tool.", "tags": "tool", + "interface": "interface.html", "supports": ["BANGLEJS","BANGLEJS2"], "allow_emulator": true, "storage": [ From ba9025172403bf61d7ec0a500e140bce7010f29b Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Fri, 29 Oct 2021 22:36:30 +0800 Subject: [PATCH 012/132] Create interface.html --- apps/authentiwatch/interface.html | 50 +++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 apps/authentiwatch/interface.html diff --git a/apps/authentiwatch/interface.html b/apps/authentiwatch/interface.html new file mode 100644 index 000000000..154f3e150 --- /dev/null +++ b/apps/authentiwatch/interface.html @@ -0,0 +1,50 @@ + + + + + +
+ + + + + + + From 36afdad86b09d54bf23891ec33cafe0b50656e79 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Sun, 31 Oct 2021 22:15:25 +0800 Subject: [PATCH 013/132] Update app.js Add widget support. Add custom font for digits. --- apps/authentiwatch/app.js | 40 ++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/apps/authentiwatch/app.js b/apps/authentiwatch/app.js index d0d951e99..cd35712b7 100644 --- a/apps/authentiwatch/app.js +++ b/apps/authentiwatch/app.js @@ -7,15 +7,19 @@ const sha256 = crypto.SHA256; const sha384 = crypto.SHA384; const sha512 = crypto.SHA512; -var tokens = require("Storage").readJSON("authentiwatch.tokens.json", true) || [ +var tokens = require("Storage").readJSON("authentiwatch.json", true) || [ {algorithm:"SHA512",digits:8,period:60,secret:"aaaa aaaa aaaa aaaa",label:"AgAgAg"}, {algorithm:"SHA1",digits:6,period:30,secret:"bbbb bbbb bbbb bbbb",label:"BgBgBg"}, {algorithm:"SHA1",digits:6,period:30,secret:"cccc cccc cccc cccc",label:"CgCgCg"}, - {algorithm:"SHA1",digits:6,period:30,secret:"xxxx xxxx xxxx xxxx",label:"XgXgXg"}, {algorithm:"SHA1",digits:6,period:60,secret:"yyyy yyyy yyyy yyyy",label:"YgYgYg"}, {algorithm:"SHA1",digits:8,period:30,secret:"zzzz zzzz zzzz zzzz",label:"ZgZgZg"}, ]; +Graphics.prototype.setFontInconsolata = function(scale) { + // Actual height 21 (25 - 5) + g.setFontCustom(atob("AAAAAAAAAAAAAAAAAAAAAAAAAAAABgAAADgAAADgAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABwAAAHwAAAfgAAB+AAAH4AAA/gAAD+AAAPwAAA/AAAB8AAABwAAAAAAAAAAAAAAAAAAAA/gAAH/8AAf//AA+A/gA4BzgAwHhgAwPBgAwcBgA54DgA/wPgAf//AAH/8AAA/gAAAAAAAAAAAAAAAAAIAAAAMAAAAYAAAAYAAAA4AAAA///gA///gA///gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAOABgAeADgA4AHgAwAPgAwAdgAwA5gAwDxgAwHhgA8fBgAf+BgAP4BgADgBgAAAAAAAAAAAAAAAAAADAAYAHAA4EDgAwMBgAwMBgAwMBgAwOBgA4+BgA///gAfz/AAHB+AAAAAAAAAAAAAAAAAAAwAAABwAAAHwAAAPwAAA+wAAB4wAAHwwAAPAwAA///gA///gA///gAAAwAAAAwAAAAQAAAAAAAAAAAAP8GAA/8HAA/8DgAwYBgAwYBgAwYBgAwYBgAwYBgAwcHgAwP/AAwH+AAAD4AAAAAAAAAAAAAHAAAD/8AAP/+AAfufAA8cDgA4YBgAwYBgAwYBgAwYBgAwcHgA4P/AAYH+AAAB4AAAAAAAAAAAAAAAAAwAAAAwAAAAwAAAAwAHgAwA/gAwH/gAwf4AAz/AAA/4AAA/AAAA8AAAAgAAAAAAAAAAAAAAAAcAAHB+AAfj/AA/3DgA4+BgAwcBgAwcBgAwcBgAw+BgA/3DgAfz/AAPB+AAAA8AAAAAAAAAAAABAAAAP4BAAf8DgA8eDgAwGBgAwGBgAwGBgAwGBgA4GDgA+OfAAf/+AAP/4AAB/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYBgAAcDgAAcDgAAYBgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="), 46, 15, 30+(scale<<8)+(1<<16)); +}; + // QR Code Text // // Example: @@ -32,7 +36,7 @@ function b32decode(seedstr) { // RFC4648 var i, buf = 0, bitcount = 0, retstr = ""; for (i in seedstr) { - let c = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567".indexOf(seedstr.charAt(i).toUpperCase(), 0); + var c = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567".indexOf(seedstr.charAt(i).toUpperCase(), 0); if (c != -1) { buf <<= 5; buf |= c; @@ -83,7 +87,7 @@ function do_hmac(key, message, algo) { var istr = new Uint8Array(blksz + message.length); var ostr = new Uint8Array(blksz + retsz); for (var i = 0; i < blksz; ++i) { - let c = (i < key.length) ? key[i] : 0; + var c = (i < key.length) ? key[i] : 0; istr[i] = c ^ 0x36; ostr[i] = c ^ 0x5C; } @@ -125,6 +129,8 @@ function drawToken(id, r) { var x2 = r.x + r.w - 1; var y2 = r.y + r.h - 1; var ylabel; + g.setClipRect(Math.max(x1, Bangle.appRect.x ), Math.max(y1, Bangle.appRect.y ), + Math.min(x2, Bangle.appRect.x2), Math.min(y2, Bangle.appRect.y2)); if (id == state.curtoken) { // current token g.setColor(g.theme.fgH); @@ -145,8 +151,8 @@ function drawToken(id, r) { g.drawString(tokens[id].label, x2 / 2, ylabel, false); if (id == state.curtoken) { // digits just below label - g.setFont6x15(2); - g.drawString(state.otp, x2 / 2, y1 + 17, false); + g.setFontInconsolata(1); + g.drawString(state.otp, x2 / 2, y1 + 12, false); // draw progress bar let xr = Math.floor(g.getWidth() * state.rem / tokens[id].period); g.fillRect(x1, y2 - 4, xr, y2 - 1); @@ -159,6 +165,7 @@ function drawToken(id, r) { } g.drawLine(x1, y1, x2, y1); g.drawLine(x1, y2, x2, y2); + g.setClipRect(0, 0, g.getWidth(), g.getHeight()); } function draw() { @@ -180,9 +187,9 @@ function draw() { if (tokens.length > 0) { var drewcur = false; var id = Math.floor(state.listy / tokenentryheight); - var y = id * tokenentryheight - state.listy; + var y = id * tokenentryheight + Bangle.appRect.y - state.listy; while (id < tokens.length && y < g.getHeight()) { - drawToken(id, {x:0, y:y, w:g.getWidth(), h:tokenentryheight}); + drawToken(id, {x:Bangle.appRect.x, y:y, w:Bangle.appRect.w, h:tokenentryheight}); if (id == state.curtoken && state.nextTime != 0) { drewcur = true; } @@ -203,7 +210,7 @@ function draw() { } function onTouch(zone, e) { - var id = Math.floor((state.listy + e.y) / tokenentryheight); + var id = Math.floor((state.listy + (e.y - Bangle.appRect.y)) / tokenentryheight); if (id == state.curtoken) { id = -1; } @@ -215,8 +222,8 @@ function onTouch(zone, e) { y = 0; } y += tokenentryheight; - if (y > g.getHeight()) { - state.listy += (y - g.getHeight()); + if (y > Bangle.appRect.h) { + state.listy += (y - Bangle.appRect.h); } } state.nextTime = 0; @@ -228,7 +235,7 @@ function onTouch(zone, e) { function onDrag(e) { if (e.x > g.getWidth() || e.y > g.getHeight()) return; if (e.dx == 0 && e.dy == 0) return; - var maxy = tokens.length * tokenentryheight - g.getHeight(); + var maxy = tokens.length * tokenentryheight - Bangle.appRect.h; var newy = state.listy - e.dy; if (newy > maxy) { newy = maxy; @@ -248,17 +255,12 @@ function onSwipe(e) { } } -function tokenSelected(id) { - state.curtoken = (id == state.curtoken) ? -1 : id; - scroller.drawMenu(); -} - Bangle.on('touch', onTouch); Bangle.on('drag' , onDrag ); Bangle.on('swipe', onSwipe); +Bangle.loadWidgets(); // Clear the screen once, at startup g.clear(); draw(); - -//var scroller = E.showScroller({h:tokenentryheight,c:tokens.length,draw:drawToken,select:tokenSelected}); +Bangle.drawWidgets(); From e373988fea6c4b9fba9a05078342fc539fc6f18e Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Sun, 31 Oct 2021 22:16:46 +0800 Subject: [PATCH 014/132] Update interface.html Implement token editing. --- apps/authentiwatch/interface.html | 296 +++++++++++++++++++++++++----- 1 file changed, 252 insertions(+), 44 deletions(-) diff --git a/apps/authentiwatch/interface.html b/apps/authentiwatch/interface.html index 154f3e150..255c5e4ca 100644 --- a/apps/authentiwatch/interface.html +++ b/apps/authentiwatch/interface.html @@ -1,50 +1,258 @@ + - - - - -
- - - - - + + + - +function onInit() { + loadTokens(); + updateTokens(); +} + + + +

Authentiwatch

+
+

No watch comms.

+
+
+ + + +
+
+
+
+
+
+ +
+
+ + + From f8bef1781201d8868de10fbf5d58dc55959f2155 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Sun, 31 Oct 2021 22:17:27 +0800 Subject: [PATCH 015/132] Create qr_packed.js --- apps/authentiwatch/qr_packed.js | 107 ++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 apps/authentiwatch/qr_packed.js diff --git a/apps/authentiwatch/qr_packed.js b/apps/authentiwatch/qr_packed.js new file mode 100644 index 000000000..28b1bddd0 --- /dev/null +++ b/apps/authentiwatch/qr_packed.js @@ -0,0 +1,107 @@ +/* Packed with Google Closure +* +* Ported to JavaScript by Lazar Laszlo 2011 +* lazarsoft@gmail.com, www.lazarsoft.info +* +* Copyright 2007 ZXing authors +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +var qrcode=function(){"use strict";function a(h,b){this.count=h;this.dataCodewords=b;this.__defineGetter__("Count",function(){return this.count});this.__defineGetter__("DataCodewords",function(){return this.dataCodewords})}function f(h,b,e){this.ecCodewordsPerBlock=h;this.ecBlocks=e?[b,e]:Array(b);this.__defineGetter__("ECCodewordsPerBlock",function(){return this.ecCodewordsPerBlock});this.__defineGetter__("TotalECCodewords",function(){return this.ecCodewordsPerBlock*this.NumBlocks});this.__defineGetter__("NumBlocks", +function(){for(var d=0,c=0;cMath.abs(d-b);if(h){var a=b;b=e;e=a;a=d;d=c;c=a}for(var m=Math.abs(d-b),f=Math.abs(c-e),q=-m>>1,k=ed?(h=b/(b-d),d=0):d>=g.width&&(h=(g.width-1-b)/(d-b),d=g.width-1);c=Math.floor(e-(c-e)*h);h=1;0>c?(h=e/(e-c),c=0):c>=g.height&&(h=(g.height-1-e)/(c-e),c=g.height-1);d=Math.floor(b+(d-b)*h);a+=this.sizeOfBlackWhiteBlackRun(b,e,d,c);return a-1};this.calculateModuleSizeOneWay=function(b,e){var d=this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(b.X), +Math.floor(b.Y),Math.floor(e.X),Math.floor(e.Y)),c=this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(e.X),Math.floor(e.Y),Math.floor(b.X),Math.floor(b.Y));return isNaN(d)?c/7:isNaN(c)?d/7:(d+c)/14};this.calculateModuleSize=function(b,e,d){return(this.calculateModuleSizeOneWay(b,e)+this.calculateModuleSizeOneWay(b,d))/2};this.distance=function(b,e){var d=b.X-e.X,c=b.Y-e.Y;return Math.sqrt(d*d+c*c)};this.computeDimension=function(b,e,d,c){e=Math.round(this.distance(b,e)/c);b=Math.round(this.distance(b, +d)/c);b=(e+b>>1)+7;switch(b&3){case 0:b++;break;case 2:b--;break;case 3:throw"Error";}return b};this.findAlignmentInRegion=function(b,e,d,c){c=Math.floor(c*b);var h=Math.max(0,e-c);e=Math.min(g.width-1,e+c);if(e-h<3*b)throw"Error";var a=Math.max(0,d-c);return(new R(this.image,h,a,e-h,Math.min(g.height-1,d+c)-a,b,this.resultPointCallback)).find()};this.createTransform=function(b,e,d,c,h){h-=3.5;var a;if(null!=c){var p=c.X;c=c.Y;var f=a=h-3}else p=e.X-b.X+d.X,c=e.Y-b.Y+d.Y,f=a=h;return z.quadrilateralToQuadrilateral(3.5, +3.5,h,3.5,f,a,3.5,h,b.X,b.Y,e.X,e.Y,p,c,d.X,d.Y)};this.sampleGrid=function(b,e,d){return F.sampleGrid3(b,d,e)};this.processFinderPatternInfo=function(b){var e=b.TopLeft,d=b.TopRight;b=b.BottomLeft;var c=this.calculateModuleSize(e,d,b);if(1>c)throw"Error";var h=this.computeDimension(e,d,b,c),a=k.getProvisionalVersionForDimension(h),m=a.DimensionForVersion-7,f=null;if(0>3&3);this.dataMask=h&7;this.__defineGetter__("ErrorCorrectionLevel",function(){return this.errorCorrectionLevel});this.__defineGetter__("DataMask",function(){return this.dataMask});this.GetHashCode=function(){return this.errorCorrectionLevel.ordinal()<< +3|this.dataMask};this.Equals=function(b){return this.errorCorrectionLevel==b.errorCorrectionLevel&&this.dataMask==b.dataMask}}function C(h,b,e){this.ordinal_Renamed_Field=h;this.bits=b;this.name=e;this.__defineGetter__("Bits",function(){return this.bits});this.__defineGetter__("Name",function(){return this.name});this.ordinal=function(){return this.ordinal_Renamed_Field}}function I(h,b){b||(b=h);if(1>h||1>b)throw"Both dimensions must be greater than 0";this.width=h;this.height=b;var e=h>>5;0!=(h& +31)&&e++;this.rowSize=e;this.bits=Array(e*b);for(e=0;e>5)],d&31)&1)};this.set_Renamed=function(d,c){this.bits[c*this.rowSize+ +(d>>5)]|=1<<(d&31)};this.flip=function(d,c){this.bits[c*this.rowSize+(d>>5)]^=1<<(d&31)};this.clear=function(){for(var d=this.bits.length,c=0;cc||0>d)throw"Left and top must be nonnegative";if(1>b||1>e)throw"Height and width must be at least 1";e=d+e;b=c+b;if(b>this.height||e>this.width)throw"The region must fit inside the matrix";for(;c>5)]|=1<<(a&31)}}function G(a,b){this.numDataCodewords= +a;this.codewords=b;this.__defineGetter__("NumDataCodewords",function(){return this.numDataCodewords});this.__defineGetter__("Codewords",function(){return this.codewords})}function T(a){var b=a.Dimension;if(21>b||1!=(b&3))throw"Error BitMatrixParser";this.bitMatrix=a;this.parsedFormatInfo=this.parsedVersion=null;this.copyBit=function(e,d,c){return this.bitMatrix.get_Renamed(e,d)?c<<1|1:c<<1};this.readFormatInformation=function(){if(null!=this.parsedFormatInfo)return this.parsedFormatInfo;for(var e= +0,d=0;6>d;d++)e=this.copyBit(d,8,e);e=this.copyBit(7,8,e);e=this.copyBit(8,8,e);e=this.copyBit(8,7,e);for(d=5;0<=d;d--)e=this.copyBit(8,d,e);this.parsedFormatInfo=r.decodeFormatInformation(e);if(null!=this.parsedFormatInfo)return this.parsedFormatInfo;for(var c=this.bitMatrix.Dimension,e=0,b=c-8,d=c-1;d>=b;d--)e=this.copyBit(d,8,e);for(d=c-7;d>2;if(6>=d)return k.getVersionForNumber(d);for(var d=0,c=e-11,b=5;0<=b;b--)for(var a=e-9;a>=c;a--)d=this.copyBit(a,b,d);this.parsedVersion=k.decodeVersionInformation(d);if(null!=this.parsedVersion&&this.parsedVersion.DimensionForVersion==e)return this.parsedVersion;d=0;for(a=5;0<=a;a--)for(b=e-9;b>=c;b--)d=this.copyBit(a,b,d);this.parsedVersion=k.decodeVersionInformation(d);if(null!= +this.parsedVersion&&this.parsedVersion.DimensionForVersion==e)return this.parsedVersion;throw"Error readVersion";};this.readCodewords=function(){var b=this.readFormatInformation(),d=this.readVersion(),c=H.forReference(b.DataMask),b=this.bitMatrix.Dimension;c.unmaskBitMatrix(this.bitMatrix,b);for(var c=d.buildFunctionPattern(),a=!0,h=Array(d.TotalCodewords),m=0,f=0,g=0,k=b-1;0t;t++)c.get_Renamed(k-t,v)||(g++,f<<=1,this.bitMatrix.get_Renamed(k- +t,v)&&(f|=1),8==g&&(h[m++]=f,f=g=0));a^=1}if(m!=d.TotalCodewords)throw"Error readCodewords";return h}}function w(a,b){if(null==b||0==b.length)throw"System.ArgumentException";this.field=a;var e=b.length;if(1c.length){var b=d,d=c;c=b}for(var b=Array(c.length),e=c.length-d.length,h=0;hc)throw"System.ArgumentException";if(0==d)return this.field.Zero;for(var b=this.coefficients.length,e=Array(b+c),a=0;a=c.Degree&&!b.Zero;)var a=b.Degree-c.Degree, +h=this.field.multiply(b.getCoefficient(b.Degree),e),f=c.multiplyByMonomial(a,h),a=this.field.buildMonomial(a,h),d=d.addOrSubtract(a),b=b.addOrSubtract(f);return[d,b]}}function n(a){this.expTable=Array(256);this.logTable=Array(256);for(var b=1,e=0;256>e;e++)this.expTable[e]=b,b<<=1,256<=b&&(b^=a);for(e=0;255>e;e++)this.logTable[this.expTable[e]]=e;a=Array(1);a[0]=0;this.zero=new w(this,Array(a));a=Array(1);a[0]=1;this.one=new w(this,Array(a));this.__defineGetter__("Zero",function(){return this.zero}); +this.__defineGetter__("One",function(){return this.one});this.buildMonomial=function(d,c){if(0>d)throw"System.ArgumentException";if(0==c)return this.zero;for(var b=Array(d+1),e=0;e>b:(a>>b)+(2<<~b)}function U(a,b,e){this.x=a;this.y=b;this.count=1;this.estimatedModuleSize=e;this.__defineGetter__("EstimatedModuleSize",function(){return this.estimatedModuleSize});this.__defineGetter__("Count",function(){return this.count});this.__defineGetter__("X",function(){return this.x});this.__defineGetter__("Y",function(){return this.y});this.incrementCount=function(){this.count++}; +this.aboutEquals=function(d,c,b){return Math.abs(c-this.y)<=d&&Math.abs(b-this.x)<=d?(d=Math.abs(d-this.estimatedModuleSize),1>=d||1>=d/this.estimatedModuleSize):!1}}function V(a){this.bottomLeft=a[0];this.topLeft=a[1];this.topRight=a[2];this.__defineGetter__("BottomLeft",function(){return this.bottomLeft});this.__defineGetter__("TopLeft",function(){return this.topLeft});this.__defineGetter__("TopRight",function(){return this.topRight})}function S(){this.image=null;this.possibleCenters=[];this.hasSkipped= +!1;this.crossCheckStateCount=[0,0,0,0,0];this.resultPointCallback=null;this.__defineGetter__("CrossCheckStateCount",function(){this.crossCheckStateCount[0]=0;this.crossCheckStateCount[1]=0;this.crossCheckStateCount[2]=0;this.crossCheckStateCount[3]=0;this.crossCheckStateCount[4]=0;return this.crossCheckStateCount});this.foundPatternCross=function(a){for(var b=0,e=0;5>e;e++){var d=a[e];if(0==d)return!1;b+=d}if(7>b)return!1;b=Math.floor((b<m)return NaN;for(;0<=m&&!c[b+m*g.width]&&l[1]<=e;)l[1]++,m--;if(0>m||l[1]>e)return NaN;for(;0<=m&&c[b+m*g.width]&&l[0]<=e;)l[0]++,m--;if(l[0]>e)return NaN;for(m=a+1;m=e)return NaN;for(;m=e||5*Math.abs(l[0]+l[1]+l[2]+l[3]+l[4]-d)>=2*d?NaN:this.foundPatternCross(l)?this.centerFromEnd(l,m):NaN};this.crossCheckHorizontal=function(a,b,e,d){for(var c=this.image,h=g.width,l=this.CrossCheckStateCount,m=a;0<=m&&c[m+b*g.width];)l[2]++,m--;if(0>m)return NaN;for(;0<=m&&!c[m+b*g.width]&&l[1]<=e;)l[1]++,m--;if(0>m||l[1]>e)return NaN;for(;0<=m&&c[m+b*g.width]&&l[0]<= +e;)l[0]++,m--;if(l[0]>e)return NaN;for(m=a+1;m=e)return NaN;for(;m=e||5*Math.abs(l[0]+l[1]+l[2]+l[3]+l[4]-d)>=d?NaN:this.foundPatternCross(l)?this.centerFromEnd(l,m):NaN};this.handlePossibleCenter=function(a,b,e){var d=a[0]+a[1]+a[2]+a[3]+a[4];e=this.centerFromEnd(a,e);b=this.crossCheckVertical(b,Math.floor(e),a[2],d);if(!isNaN(b)&&(e=this.crossCheckHorizontal(Math.floor(e), +Math.floor(b),a[2],d),!isNaN(e))){a=d/7;for(var d=!1,c=this.possibleCenters.length,h=0;ha)throw"Couldn't find enough finder patterns (found "+a+")";if(3a&&this.possibleCenters.splice(d,1)}3d.count?-1:c.count=a)return 0;for(var b=null,e=0;e=K)if(null==b)b=d;else return this.hasSkipped=!0,Math.floor((Math.abs(b.X-d.X)-Math.abs(b.Y-d.Y))/2)}return 0};this.haveMultiplyConfirmedCenters=function(){for(var a,b=0,e=0,d=this.possibleCenters.length,c=0;c=K&&(b++,e+=a.EstimatedModuleSize); +if(3>b)return!1;for(var b=e/d,p=0,c=0;cl[2]&&(m+=b-l[2]-c,f=d-1));else{do f++;while(f=d||1>=d/this.estimatedModuleSize):!1}}function R(a,b,e,d,c,f,l){this.image=a;this.possibleCenters= +[];this.startX=b;this.startY=e;this.width=d;this.height=c;this.moduleSize=f;this.crossCheckStateCount=[0,0,0];this.resultPointCallback=l;this.centerFromEnd=function(c,d){return d-c[2]-c[1]/2};this.foundPatternCross=function(c){for(var d=this.moduleSize,b=d/2,a=0;3>a;a++)if(Math.abs(d-c[a])>=b)return!1;return!0};this.crossCheckVertical=function(c,d,b,a){var e=this.image,h=g.height,f=this.crossCheckStateCount;f[0]=0;f[1]=0;f[2]=0;for(var l=c;0<=l&&e[d+l*g.width]&&f[1]<=b;)f[1]++,l--;if(0>l||f[1]>b)return NaN; +for(;0<=l&&!e[d+l*g.width]&&f[0]<=b;)f[0]++,l--;if(f[0]>b)return NaN;for(l=c+1;lb)return NaN;for(;lb||5*Math.abs(f[0]+f[1]+f[2]-a)>=2*a?NaN:this.foundPatternCross(f)?this.centerFromEnd(f,l):NaN};this.handlePossibleCenter=function(c,d,b){var a=c[0]+c[1]+c[2];b=this.centerFromEnd(c,b);d=this.crossCheckVertical(d,Math.floor(b),2*c[1],a);if(!isNaN(d)){c=(c[0]+c[1]+c[2])/3;for(var a=this.possibleCenters.length, +e=0;e>1),p=[0,0,0],k=0;k>1:-(k+1>>1));p[0]=0;p[1]=0;p[2]=0;for(var A=b;A=b?this.dataLengthMode=0:10<=b&&26>=b?this.dataLengthMode=1:27<= +b&&40>=b&&(this.dataLengthMode=2);this.getNextBits=function(b){var c,d;if(b>this.bitPointer-b+1;this.bitPointer-=b;return d}if(b>8-(b-(this.bitPointer+1));this.bitPointer-=b%8;0>this.bitPointer&&(this.bitPointer= +8+this.bitPointer);return d}if(b>8-(b-(this.bitPointer+1+8));this.bitPointer-=(b-8)%8;0>this.bitPointer&&(this.bitPointer=8+this.bitPointer);return c+e+d}return 0}; +this.NextMode=function(){return this.blockPointer>this.blocks.length-this.numErrorCorrectionCode-2?0:this.getNextBits(4)};this.getDataLength=function(b){for(var c=0;1!=b>>c;)c++;return this.getNextBits(g.sizeOfDataLengthInfo[this.dataLengthMode][c])};this.getRomanAndFigureString=function(b){var c="",d="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:".split("");do if(1c&&(d+="0"),10>c&&(d+="0"),b-=3):2==b?(c=this.getNextBits(7),10>c&&(d+="0"),b-=2):1==b&&(c=this.getNextBits(4),--b),d+=c;while(0=d+33088?d+33088:d+49472);b--}while(0< +b);return c};this.parseECIValue=function(){var b=0,c=this.getNextBits(8);0==(c&128)&&(b=c&127);128==(c&192)&&(b=this.getNextBits(8),b|=(c&63)<<8);192==(c&224)&&(b=this.getNextBits(8),b|=(c&31)<<16);return b};this.__defineGetter__("DataByte",function(){var b=[];do{var c=this.NextMode();if(0==c)if(0a)throw"Invalid data length: "+a;switch(c){case 1:c=this.getFigureString(a);for(var a=Array(c.length),e=0;ed||d>c||-1>e||e>h)throw"Error.checkAndNudgePoints ";f=!1;-1==d?(b[m]=0,f=!0):d==c&&(b[m]=c-1,f=!0);-1==e?(b[m+1]=0,f=!0):e==h&&(b[m+1]=h-1,f=!0)}f=!0;for(m=b.length-2;0<=m&&f;m-=2){d=Math.floor(b[m]);e=Math.floor(b[m+1]);if(-1>d||d>c||-1>e||e>h)throw"Error.checkAndNudgePoints ";f=!1;-1==d?(b[m]=0,f=!0):d==c&&(b[m]=c-1,f=!0);-1==e?(b[m+1]=0,f=!0):e==h&&(b[m+1]=h-1,f=!0)}},sampleGrid3:function(a,b,e){for(var d=new I(b),c=Array(b<<1),h=0;h>1)+.5,c[k+1]=m;e.transformPoints1(c);F.checkAndNudgePoints(a,c);try{for(k=0;k>1,h)}catch(q){throw"Error.checkAndNudgePoints";}}return d},sampleGridx:function(a,b,e,d,c,f,l,g,k,q,n,x,v,t,r,A,u,w){e=z.quadrilateralToQuadrilateral(e,d,c,f,l,g,k,q,n,x,v,t,r,A,u,w);return F.sampleGrid3(a,b,e)}};k.VERSION_DECODE_INFO=[31892,34236,39577,42195,48118,51042,55367,58893,63784,68472,70749,76311,79154, +84390,87683,92361,96236,102084,102881,110507,110734,117786,119615,126325,127568,133589,136944,141498,145311,150283,152622,158308,161089,167017];k.VERSIONS=[new k(1,[],new f(7,new a(1,19)),new f(10,new a(1,16)),new f(13,new a(1,13)),new f(17,new a(1,9))),new k(2,[6,18],new f(10,new a(1,34)),new f(16,new a(1,28)),new f(22,new a(1,22)),new f(28,new a(1,16))),new k(3,[6,22],new f(15,new a(1,55)),new f(26,new a(1,44)),new f(18,new a(2,17)),new f(22,new a(2,13))),new k(4,[6,26],new f(20,new a(1,80)),new f(18, +new a(2,32)),new f(26,new a(2,24)),new f(16,new a(4,9))),new k(5,[6,30],new f(26,new a(1,108)),new f(24,new a(2,43)),new f(18,new a(2,15),new a(2,16)),new f(22,new a(2,11),new a(2,12))),new k(6,[6,34],new f(18,new a(2,68)),new f(16,new a(4,27)),new f(24,new a(4,19)),new f(28,new a(4,15))),new k(7,[6,22,38],new f(20,new a(2,78)),new f(18,new a(4,31)),new f(18,new a(2,14),new a(4,15)),new f(26,new a(4,13),new a(1,14))),new k(8,[6,24,42],new f(24,new a(2,97)),new f(22,new a(2,38),new a(2,39)),new f(22, +new a(4,18),new a(2,19)),new f(26,new a(4,14),new a(2,15))),new k(9,[6,26,46],new f(30,new a(2,116)),new f(22,new a(3,36),new a(2,37)),new f(20,new a(4,16),new a(4,17)),new f(24,new a(4,12),new a(4,13))),new k(10,[6,28,50],new f(18,new a(2,68),new a(2,69)),new f(26,new a(4,43),new a(1,44)),new f(24,new a(6,19),new a(2,20)),new f(28,new a(6,15),new a(2,16))),new k(11,[6,30,54],new f(20,new a(4,81)),new f(30,new a(1,50),new a(4,51)),new f(28,new a(4,22),new a(4,23)),new f(24,new a(3,12),new a(8,13))), +new k(12,[6,32,58],new f(24,new a(2,92),new a(2,93)),new f(22,new a(6,36),new a(2,37)),new f(26,new a(4,20),new a(6,21)),new f(28,new a(7,14),new a(4,15))),new k(13,[6,34,62],new f(26,new a(4,107)),new f(22,new a(8,37),new a(1,38)),new f(24,new a(8,20),new a(4,21)),new f(22,new a(12,11),new a(4,12))),new k(14,[6,26,46,66],new f(30,new a(3,115),new a(1,116)),new f(24,new a(4,40),new a(5,41)),new f(20,new a(11,16),new a(5,17)),new f(24,new a(11,12),new a(5,13))),new k(15,[6,26,48,70],new f(22,new a(5, +87),new a(1,88)),new f(24,new a(5,41),new a(5,42)),new f(30,new a(5,24),new a(7,25)),new f(24,new a(11,12),new a(7,13))),new k(16,[6,26,50,74],new f(24,new a(5,98),new a(1,99)),new f(28,new a(7,45),new a(3,46)),new f(24,new a(15,19),new a(2,20)),new f(30,new a(3,15),new a(13,16))),new k(17,[6,30,54,78],new f(28,new a(1,107),new a(5,108)),new f(28,new a(10,46),new a(1,47)),new f(28,new a(1,22),new a(15,23)),new f(28,new a(2,14),new a(17,15))),new k(18,[6,30,56,82],new f(30,new a(5,120),new a(1,121)), +new f(26,new a(9,43),new a(4,44)),new f(28,new a(17,22),new a(1,23)),new f(28,new a(2,14),new a(19,15))),new k(19,[6,30,58,86],new f(28,new a(3,113),new a(4,114)),new f(26,new a(3,44),new a(11,45)),new f(26,new a(17,21),new a(4,22)),new f(26,new a(9,13),new a(16,14))),new k(20,[6,34,62,90],new f(28,new a(3,107),new a(5,108)),new f(26,new a(3,41),new a(13,42)),new f(30,new a(15,24),new a(5,25)),new f(28,new a(15,15),new a(10,16))),new k(21,[6,28,50,72,94],new f(28,new a(4,116),new a(4,117)),new f(26, +new a(17,42)),new f(28,new a(17,22),new a(6,23)),new f(30,new a(19,16),new a(6,17))),new k(22,[6,26,50,74,98],new f(28,new a(2,111),new a(7,112)),new f(28,new a(17,46)),new f(30,new a(7,24),new a(16,25)),new f(24,new a(34,13))),new k(23,[6,30,54,74,102],new f(30,new a(4,121),new a(5,122)),new f(28,new a(4,47),new a(14,48)),new f(30,new a(11,24),new a(14,25)),new f(30,new a(16,15),new a(14,16))),new k(24,[6,28,54,80,106],new f(30,new a(6,117),new a(4,118)),new f(28,new a(6,45),new a(14,46)),new f(30, +new a(11,24),new a(16,25)),new f(30,new a(30,16),new a(2,17))),new k(25,[6,32,58,84,110],new f(26,new a(8,106),new a(4,107)),new f(28,new a(8,47),new a(13,48)),new f(30,new a(7,24),new a(22,25)),new f(30,new a(22,15),new a(13,16))),new k(26,[6,30,58,86,114],new f(28,new a(10,114),new a(2,115)),new f(28,new a(19,46),new a(4,47)),new f(28,new a(28,22),new a(6,23)),new f(30,new a(33,16),new a(4,17))),new k(27,[6,34,62,90,118],new f(30,new a(8,122),new a(4,123)),new f(28,new a(22,45),new a(3,46)),new f(30, +new a(8,23),new a(26,24)),new f(30,new a(12,15),new a(28,16))),new k(28,[6,26,50,74,98,122],new f(30,new a(3,117),new a(10,118)),new f(28,new a(3,45),new a(23,46)),new f(30,new a(4,24),new a(31,25)),new f(30,new a(11,15),new a(31,16))),new k(29,[6,30,54,78,102,126],new f(30,new a(7,116),new a(7,117)),new f(28,new a(21,45),new a(7,46)),new f(30,new a(1,23),new a(37,24)),new f(30,new a(19,15),new a(26,16))),new k(30,[6,26,52,78,104,130],new f(30,new a(5,115),new a(10,116)),new f(28,new a(19,47),new a(10, +48)),new f(30,new a(15,24),new a(25,25)),new f(30,new a(23,15),new a(25,16))),new k(31,[6,30,56,82,108,134],new f(30,new a(13,115),new a(3,116)),new f(28,new a(2,46),new a(29,47)),new f(30,new a(42,24),new a(1,25)),new f(30,new a(23,15),new a(28,16))),new k(32,[6,34,60,86,112,138],new f(30,new a(17,115)),new f(28,new a(10,46),new a(23,47)),new f(30,new a(10,24),new a(35,25)),new f(30,new a(19,15),new a(35,16))),new k(33,[6,30,58,86,114,142],new f(30,new a(17,115),new a(1,116)),new f(28,new a(14,46), +new a(21,47)),new f(30,new a(29,24),new a(19,25)),new f(30,new a(11,15),new a(46,16))),new k(34,[6,34,62,90,118,146],new f(30,new a(13,115),new a(6,116)),new f(28,new a(14,46),new a(23,47)),new f(30,new a(44,24),new a(7,25)),new f(30,new a(59,16),new a(1,17))),new k(35,[6,30,54,78,102,126,150],new f(30,new a(12,121),new a(7,122)),new f(28,new a(12,47),new a(26,48)),new f(30,new a(39,24),new a(14,25)),new f(30,new a(22,15),new a(41,16))),new k(36,[6,24,50,76,102,128,154],new f(30,new a(6,121),new a(14, +122)),new f(28,new a(6,47),new a(34,48)),new f(30,new a(46,24),new a(10,25)),new f(30,new a(2,15),new a(64,16))),new k(37,[6,28,54,80,106,132,158],new f(30,new a(17,122),new a(4,123)),new f(28,new a(29,46),new a(14,47)),new f(30,new a(49,24),new a(10,25)),new f(30,new a(24,15),new a(46,16))),new k(38,[6,32,58,84,110,136,162],new f(30,new a(4,122),new a(18,123)),new f(28,new a(13,46),new a(32,47)),new f(30,new a(48,24),new a(14,25)),new f(30,new a(42,15),new a(32,16))),new k(39,[6,26,54,82,110,138, +166],new f(30,new a(20,117),new a(4,118)),new f(28,new a(40,47),new a(7,48)),new f(30,new a(43,24),new a(22,25)),new f(30,new a(10,15),new a(67,16))),new k(40,[6,30,58,86,114,142,170],new f(30,new a(19,118),new a(6,119)),new f(28,new a(18,47),new a(31,48)),new f(30,new a(34,24),new a(34,25)),new f(30,new a(20,15),new a(61,16)))];k.getVersionForNumber=function(a){if(1>a||40>2)}catch(b){throw"Error getVersionForNumber";}};k.decodeVersionInformation=function(a){for(var b=4294967295,e=0,d=0;d=b?this.getVersionForNumber(e):null};z.quadrilateralToQuadrilateral=function(a,b,e,d,c,f,g,m,k,q,n,x,v,t,r,u){a=this.quadrilateralToSquare(a,b,e,d,c,f,g,m);return this.squareToQuadrilateral(k, +q,n,x,v,t,r,u).times(a)};z.squareToQuadrilateral=function(a,b,e,d,c,f,g,m){var h=m-f,l=b-d+f-m;if(0==h&&0==l)return new z(e-a,c-e,a,d-b,f-d,b,0,0,1);var p=e-c,k=g-c;c=a-e+c-g;f=d-f;var n=p*h-k*f,h=(c*h-k*l)/n,l=(p*l-c*f)/n;return new z(e-a+h*e,g-a+l*g,a,d-b+h*d,m-b+l*m,b,h,l,1)};z.quadrilateralToSquare=function(a,b,e,d,c,f,g,m){return this.squareToQuadrilateral(a,b,e,d,c,f,g,m).buildAdjoint()};var N=[[21522,0],[20773,1],[24188,2],[23371,3],[17913,4],[16590,5],[20375,6],[19104,7],[30660,8],[29427, +9],[32170,10],[30877,11],[26159,12],[25368,13],[27713,14],[26998,15],[5769,16],[5054,17],[7399,18],[6608,19],[1890,20],[597,21],[3340,22],[2107,23],[13663,24],[12392,25],[16177,26],[14854,27],[9396,28],[8579,29],[11994,30],[11245,31]],B=[0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4];r.numBitsDiffering=function(a,b){a^=b;return B[a&15]+B[u(a,4)&15]+B[u(a,8)&15]+B[u(a,12)&15]+B[u(a,16)&15]+B[u(a,20)&15]+B[u(a,24)&15]+B[u(a,28)&15]};r.decodeFormatInformation=function(a){var b=r.doDecodeFormatInformation(a);return null!= +b?b:r.doDecodeFormatInformation(a^21522)};r.doDecodeFormatInformation=function(a){for(var b=4294967295,e=0,d=0;d=b?new r(e):null};C.forBits=function(a){if(0>a||a>=O.length)throw"ArgumentException";return O[a]};var Y=new C(0,1,"L"),Z=new C(1,0,"M"),aa=new C(2,3,"Q"),ba=new C(3,2,"H"),O=[Z,Y,ba,aa];G.getDataBlocks=function(a,b,e){if(a.length!=b.TotalCodewords)throw"ArgumentException"; +var d=b.getECBlocksForLevel(e);e=0;var c=d.getECBlocks();for(b=0;ba||7h)throw"ReedSolomonException Bad error location";a[h]=n.addOrSubtract(a[h],c[f])}};this.runEuclideanAlgorithm=function(a,e,d){if(a.Degree=Math.floor(d/2);){var k=a,q=b,n=h;a=e;b=f;h=g;if(a.Zero)throw"r_{i-1} was zero";e=k;g=this.field.Zero;f=a.getCoefficient(a.Degree); +for(f=this.field.inverse(f);e.Degree>=a.Degree&&!e.Zero;){var k=e.Degree-a.Degree,r=this.field.multiply(e.getCoefficient(e.Degree),f),g=g.addOrSubtract(this.field.buildMonomial(k,r));e=e.addOrSubtract(a.multiplyByMonomial(k,r))}f=g.multiply1(b).addOrSubtract(q);g=g.multiply1(h).addOrSubtract(n)}d=g.getCoefficient(0);if(0==d)throw"ReedSolomonException sigmaTilde(0) was zero";d=this.field.inverse(d);a=g.multiply2(d);d=e.multiply2(d);return[a,d]};this.findErrorLocations=function(a){var b=a.Degree;if(1== +b)return Array(a.getCoefficient(1));for(var d=Array(b),c=0,f=1;256>f&&cg.maxImgSize&&(f=d.width/d.height,e=Math.sqrt(g.maxImgSize/f),f*=e);a.width=f;a.height=e;b.drawImage(d,0,0,a.width,a.height);g.width=a.width;g.height=a.height;try{g.imagedata= +b.getImageData(0,0,a.width,a.height)}catch(y){g.result=Error("Cross domain image reading not supported in your browser! Save it to your computer then drag and drop the file!");null!=g.callback&&g.callback(g.result);return}try{g.result=g.process(b)}catch(y){console.log(y),g.result=Error("error decoding QR Code")}null!=g.callback&&g.callback(g.result)};d.onerror=function(){null!=g.callback&&g.callback(Error("Failed to load the image"))};d.src=a},isUrl:function(a){return/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/.test(a)}, +decode_url:function(a){var b="";try{b=escape(a)}catch(e){console.log(e),b=a}a="";try{a=decodeURIComponent(b)}catch(e){console.log(e),a=b}return a},decode_utf8:function(a){return g.isUrl(a)?g.decode_url(a):a},process:function(a){var b=(new Date).getTime(),e=g.grayScaleToBitmap(g.grayscale());if(g.debug){for(var d=0;dc;c++){d[c]=Array(4);for(var f=0;4>f;f++)d[c][f]=[0,0]}for(c=0;4>c;c++)for(f= +0;4>f;f++){d[f][c][0]=255;for(var h=0;hd[f][c][1]&&(d[f][c][1]=k)}}a=Array(4);for(b=0;4>b;b++)a[b]=Array(4);for(c=0;4>c;c++)for(f=0;4>f;f++)a[f][c]=Math.floor((d[f][c][0]+d[f][c][1])/2);return a},grayScaleToBitmap:function(a){for(var b=g.getMiddleBrightnessPerArea(a),e=b.length,d=Math.floor(g.width/e),c=Math.floor(g.height/e),f=new ArrayBuffer(g.width*g.height),f=new Uint8Array(f),h=0;h=e&&d>=c?(d=a[0],e=a[1],c=a[2]):c>=d&&c>=e?(d=a[1], +e=a[0],c=a[2]):(d=a[2],e=a[0],c=a[1]);if(0>function(a,b,c){var d=b.x;b=b.y;return(c.x-d)*(a.y-b)-(c.y-b)*(a.x-d)}(e,d,c))var f=e,e=c,c=f;a[0]=e;a[1]=d;a[2]=c};return g}(); From c0b59266194c5de86a3a3f75bf22cce0eaba5933 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Sun, 31 Oct 2021 22:17:57 +0800 Subject: [PATCH 016/132] Create qrcode.min.js --- apps/authentiwatch/qrcode.min.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 apps/authentiwatch/qrcode.min.js diff --git a/apps/authentiwatch/qrcode.min.js b/apps/authentiwatch/qrcode.min.js new file mode 100644 index 000000000..d5f3ca88b --- /dev/null +++ b/apps/authentiwatch/qrcode.min.js @@ -0,0 +1 @@ +var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this.parsedData=[];for(var b=[],d=0,e=this.data.length;e>d;d++){var f=this.data.charCodeAt(d);f>65536?(b[0]=240|(1835008&f)>>>18,b[1]=128|(258048&f)>>>12,b[2]=128|(4032&f)>>>6,b[3]=128|63&f):f>2048?(b[0]=224|(61440&f)>>>12,b[1]=128|(4032&f)>>>6,b[2]=128|63&f):f>128?(b[0]=192|(1984&f)>>>6,b[1]=128|63&f):b[0]=f,this.parsedData=this.parsedData.concat(b)}this.parsedData.length!=this.data.length&&(this.parsedData.unshift(191),this.parsedData.unshift(187),this.parsedData.unshift(239))}function b(a,b){this.typeNumber=a,this.errorCorrectLevel=b,this.modules=null,this.moduleCount=0,this.dataCache=null,this.dataList=[]}function i(a,b){if(void 0==a.length)throw new Error(a.length+"/"+b);for(var c=0;c=f;f++){var h=0;switch(b){case d.L:h=l[f][0];break;case d.M:h=l[f][1];break;case d.Q:h=l[f][2];break;case d.H:h=l[f][3]}if(h>=e)break;c++}if(c>l.length)throw new Error("Too long data");return c}function s(a){var b=encodeURI(a).toString().replace(/\%[0-9a-fA-F]{2}/g,"a");return b.length+(b.length!=a?3:0)}a.prototype={getLength:function(){return this.parsedData.length},write:function(a){for(var b=0,c=this.parsedData.length;c>b;b++)a.put(this.parsedData[b],8)}},b.prototype={addData:function(b){var c=new a(b);this.dataList.push(c),this.dataCache=null},isDark:function(a,b){if(0>a||this.moduleCount<=a||0>b||this.moduleCount<=b)throw new Error(a+","+b);return this.modules[a][b]},getModuleCount:function(){return this.moduleCount},make:function(){this.makeImpl(!1,this.getBestMaskPattern())},makeImpl:function(a,c){this.moduleCount=4*this.typeNumber+17,this.modules=new Array(this.moduleCount);for(var d=0;d=7&&this.setupTypeNumber(a),null==this.dataCache&&(this.dataCache=b.createData(this.typeNumber,this.errorCorrectLevel,this.dataList)),this.mapData(this.dataCache,c)},setupPositionProbePattern:function(a,b){for(var c=-1;7>=c;c++)if(!(-1>=a+c||this.moduleCount<=a+c))for(var d=-1;7>=d;d++)-1>=b+d||this.moduleCount<=b+d||(this.modules[a+c][b+d]=c>=0&&6>=c&&(0==d||6==d)||d>=0&&6>=d&&(0==c||6==c)||c>=2&&4>=c&&d>=2&&4>=d?!0:!1)},getBestMaskPattern:function(){for(var a=0,b=0,c=0;8>c;c++){this.makeImpl(!0,c);var d=f.getLostPoint(this);(0==c||a>d)&&(a=d,b=c)}return b},createMovieClip:function(a,b,c){var d=a.createEmptyMovieClip(b,c),e=1;this.make();for(var f=0;f=g;g++)for(var h=-2;2>=h;h++)this.modules[d+g][e+h]=-2==g||2==g||-2==h||2==h||0==g&&0==h?!0:!1}},setupTypeNumber:function(a){for(var b=f.getBCHTypeNumber(this.typeNumber),c=0;18>c;c++){var d=!a&&1==(1&b>>c);this.modules[Math.floor(c/3)][c%3+this.moduleCount-8-3]=d}for(var c=0;18>c;c++){var d=!a&&1==(1&b>>c);this.modules[c%3+this.moduleCount-8-3][Math.floor(c/3)]=d}},setupTypeInfo:function(a,b){for(var c=this.errorCorrectLevel<<3|b,d=f.getBCHTypeInfo(c),e=0;15>e;e++){var g=!a&&1==(1&d>>e);6>e?this.modules[e][8]=g:8>e?this.modules[e+1][8]=g:this.modules[this.moduleCount-15+e][8]=g}for(var e=0;15>e;e++){var g=!a&&1==(1&d>>e);8>e?this.modules[8][this.moduleCount-e-1]=g:9>e?this.modules[8][15-e-1+1]=g:this.modules[8][15-e-1]=g}this.modules[this.moduleCount-8][8]=!a},mapData:function(a,b){for(var c=-1,d=this.moduleCount-1,e=7,g=0,h=this.moduleCount-1;h>0;h-=2)for(6==h&&h--;;){for(var i=0;2>i;i++)if(null==this.modules[d][h-i]){var j=!1;g>>e));var k=f.getMask(b,d,h-i);k&&(j=!j),this.modules[d][h-i]=j,e--,-1==e&&(g++,e=7)}if(d+=c,0>d||this.moduleCount<=d){d-=c,c=-c;break}}}},b.PAD0=236,b.PAD1=17,b.createData=function(a,c,d){for(var e=j.getRSBlocks(a,c),g=new k,h=0;h8*l)throw new Error("code length overflow. ("+g.getLengthInBits()+">"+8*l+")");for(g.getLengthInBits()+4<=8*l&&g.put(0,4);0!=g.getLengthInBits()%8;)g.putBit(!1);for(;;){if(g.getLengthInBits()>=8*l)break;if(g.put(b.PAD0,8),g.getLengthInBits()>=8*l)break;g.put(b.PAD1,8)}return b.createBytes(g,e)},b.createBytes=function(a,b){for(var c=0,d=0,e=0,g=new Array(b.length),h=new Array(b.length),j=0;j=0?p.get(q):0}}for(var r=0,m=0;mm;m++)for(var j=0;jm;m++)for(var j=0;j=0;)b^=f.G15<=0;)b^=f.G18<>>=1;return b},getPatternPosition:function(a){return f.PATTERN_POSITION_TABLE[a-1]},getMask:function(a,b,c){switch(a){case e.PATTERN000:return 0==(b+c)%2;case e.PATTERN001:return 0==b%2;case e.PATTERN010:return 0==c%3;case e.PATTERN011:return 0==(b+c)%3;case e.PATTERN100:return 0==(Math.floor(b/2)+Math.floor(c/3))%2;case e.PATTERN101:return 0==b*c%2+b*c%3;case e.PATTERN110:return 0==(b*c%2+b*c%3)%2;case e.PATTERN111:return 0==(b*c%3+(b+c)%2)%2;default:throw new Error("bad maskPattern:"+a)}},getErrorCorrectPolynomial:function(a){for(var b=new i([1],0),c=0;a>c;c++)b=b.multiply(new i([1,g.gexp(c)],0));return b},getLengthInBits:function(a,b){if(b>=1&&10>b)switch(a){case c.MODE_NUMBER:return 10;case c.MODE_ALPHA_NUM:return 9;case c.MODE_8BIT_BYTE:return 8;case c.MODE_KANJI:return 8;default:throw new Error("mode:"+a)}else if(27>b)switch(a){case c.MODE_NUMBER:return 12;case c.MODE_ALPHA_NUM:return 11;case c.MODE_8BIT_BYTE:return 16;case c.MODE_KANJI:return 10;default:throw new Error("mode:"+a)}else{if(!(41>b))throw new Error("type:"+b);switch(a){case c.MODE_NUMBER:return 14;case c.MODE_ALPHA_NUM:return 13;case c.MODE_8BIT_BYTE:return 16;case c.MODE_KANJI:return 12;default:throw new Error("mode:"+a)}}},getLostPoint:function(a){for(var b=a.getModuleCount(),c=0,d=0;b>d;d++)for(var e=0;b>e;e++){for(var f=0,g=a.isDark(d,e),h=-1;1>=h;h++)if(!(0>d+h||d+h>=b))for(var i=-1;1>=i;i++)0>e+i||e+i>=b||(0!=h||0!=i)&&g==a.isDark(d+h,e+i)&&f++;f>5&&(c+=3+f-5)}for(var d=0;b-1>d;d++)for(var e=0;b-1>e;e++){var j=0;a.isDark(d,e)&&j++,a.isDark(d+1,e)&&j++,a.isDark(d,e+1)&&j++,a.isDark(d+1,e+1)&&j++,(0==j||4==j)&&(c+=3)}for(var d=0;b>d;d++)for(var e=0;b-6>e;e++)a.isDark(d,e)&&!a.isDark(d,e+1)&&a.isDark(d,e+2)&&a.isDark(d,e+3)&&a.isDark(d,e+4)&&!a.isDark(d,e+5)&&a.isDark(d,e+6)&&(c+=40);for(var e=0;b>e;e++)for(var d=0;b-6>d;d++)a.isDark(d,e)&&!a.isDark(d+1,e)&&a.isDark(d+2,e)&&a.isDark(d+3,e)&&a.isDark(d+4,e)&&!a.isDark(d+5,e)&&a.isDark(d+6,e)&&(c+=40);for(var k=0,e=0;b>e;e++)for(var d=0;b>d;d++)a.isDark(d,e)&&k++;var l=Math.abs(100*k/b/b-50)/5;return c+=10*l}},g={glog:function(a){if(1>a)throw new Error("glog("+a+")");return g.LOG_TABLE[a]},gexp:function(a){for(;0>a;)a+=255;for(;a>=256;)a-=255;return g.EXP_TABLE[a]},EXP_TABLE:new Array(256),LOG_TABLE:new Array(256)},h=0;8>h;h++)g.EXP_TABLE[h]=1<h;h++)g.EXP_TABLE[h]=g.EXP_TABLE[h-4]^g.EXP_TABLE[h-5]^g.EXP_TABLE[h-6]^g.EXP_TABLE[h-8];for(var h=0;255>h;h++)g.LOG_TABLE[g.EXP_TABLE[h]]=h;i.prototype={get:function(a){return this.num[a]},getLength:function(){return this.num.length},multiply:function(a){for(var b=new Array(this.getLength()+a.getLength()-1),c=0;cf;f++)for(var g=c[3*f+0],h=c[3*f+1],i=c[3*f+2],k=0;g>k;k++)e.push(new j(h,i));return e},j.getRsBlockTable=function(a,b){switch(b){case d.L:return j.RS_BLOCK_TABLE[4*(a-1)+0];case d.M:return j.RS_BLOCK_TABLE[4*(a-1)+1];case d.Q:return j.RS_BLOCK_TABLE[4*(a-1)+2];case d.H:return j.RS_BLOCK_TABLE[4*(a-1)+3];default:return void 0}},k.prototype={get:function(a){var b=Math.floor(a/8);return 1==(1&this.buffer[b]>>>7-a%8)},put:function(a,b){for(var c=0;b>c;c++)this.putBit(1==(1&a>>>b-c-1))},getLengthInBits:function(){return this.length},putBit:function(a){var b=Math.floor(this.length/8);this.buffer.length<=b&&this.buffer.push(0),a&&(this.buffer[b]|=128>>>this.length%8),this.length++}};var l=[[17,14,11,7],[32,26,20,14],[53,42,32,24],[78,62,46,34],[106,84,60,44],[134,106,74,58],[154,122,86,64],[192,152,108,84],[230,180,130,98],[271,213,151,119],[321,251,177,137],[367,287,203,155],[425,331,241,177],[458,362,258,194],[520,412,292,220],[586,450,322,250],[644,504,364,280],[718,560,394,310],[792,624,442,338],[858,666,482,382],[929,711,509,403],[1003,779,565,439],[1091,857,611,461],[1171,911,661,511],[1273,997,715,535],[1367,1059,751,593],[1465,1125,805,625],[1528,1190,868,658],[1628,1264,908,698],[1732,1370,982,742],[1840,1452,1030,790],[1952,1538,1112,842],[2068,1628,1168,898],[2188,1722,1228,958],[2303,1809,1283,983],[2431,1911,1351,1051],[2563,1989,1423,1093],[2699,2099,1499,1139],[2809,2213,1579,1219],[2953,2331,1663,1273]],o=function(){var a=function(a,b){this._el=a,this._htOption=b};return a.prototype.draw=function(a){function g(a,b){var c=document.createElementNS("http://www.w3.org/2000/svg",a);for(var d in b)b.hasOwnProperty(d)&&c.setAttribute(d,b[d]);return c}var b=this._htOption,c=this._el,d=a.getModuleCount();Math.floor(b.width/d),Math.floor(b.height/d),this.clear();var h=g("svg",{viewBox:"0 0 "+String(d)+" "+String(d),width:"100%",height:"100%",fill:b.colorLight});h.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xlink","http://www.w3.org/1999/xlink"),c.appendChild(h),h.appendChild(g("rect",{fill:b.colorDark,width:"1",height:"1",id:"template"}));for(var i=0;d>i;i++)for(var j=0;d>j;j++)if(a.isDark(i,j)){var k=g("use",{x:String(i),y:String(j)});k.setAttributeNS("http://www.w3.org/1999/xlink","href","#template"),h.appendChild(k)}},a.prototype.clear=function(){for(;this._el.hasChildNodes();)this._el.removeChild(this._el.lastChild)},a}(),p="svg"===document.documentElement.tagName.toLowerCase(),q=p?o:m()?function(){function a(){this._elImage.src=this._elCanvas.toDataURL("image/png"),this._elImage.style.display="block",this._elCanvas.style.display="none"}function d(a,b){var c=this;if(c._fFail=b,c._fSuccess=a,null===c._bSupportDataURI){var d=document.createElement("img"),e=function(){c._bSupportDataURI=!1,c._fFail&&_fFail.call(c)},f=function(){c._bSupportDataURI=!0,c._fSuccess&&c._fSuccess.call(c)};return d.onabort=e,d.onerror=e,d.onload=f,d.src="data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==",void 0}c._bSupportDataURI===!0&&c._fSuccess?c._fSuccess.call(c):c._bSupportDataURI===!1&&c._fFail&&c._fFail.call(c)}if(this._android&&this._android<=2.1){var b=1/window.devicePixelRatio,c=CanvasRenderingContext2D.prototype.drawImage;CanvasRenderingContext2D.prototype.drawImage=function(a,d,e,f,g,h,i,j){if("nodeName"in a&&/img/i.test(a.nodeName))for(var l=arguments.length-1;l>=1;l--)arguments[l]=arguments[l]*b;else"undefined"==typeof j&&(arguments[1]*=b,arguments[2]*=b,arguments[3]*=b,arguments[4]*=b);c.apply(this,arguments)}}var e=function(a,b){this._bIsPainted=!1,this._android=n(),this._htOption=b,this._elCanvas=document.createElement("canvas"),this._elCanvas.width=b.width,this._elCanvas.height=b.height,a.appendChild(this._elCanvas),this._el=a,this._oContext=this._elCanvas.getContext("2d"),this._bIsPainted=!1,this._elImage=document.createElement("img"),this._elImage.style.display="none",this._el.appendChild(this._elImage),this._bSupportDataURI=null};return e.prototype.draw=function(a){var b=this._elImage,c=this._oContext,d=this._htOption,e=a.getModuleCount(),f=d.width/e,g=d.height/e,h=Math.round(f),i=Math.round(g);b.style.display="none",this.clear();for(var j=0;e>j;j++)for(var k=0;e>k;k++){var l=a.isDark(j,k),m=k*f,n=j*g;c.strokeStyle=l?d.colorDark:d.colorLight,c.lineWidth=1,c.fillStyle=l?d.colorDark:d.colorLight,c.fillRect(m,n,f,g),c.strokeRect(Math.floor(m)+.5,Math.floor(n)+.5,h,i),c.strokeRect(Math.ceil(m)-.5,Math.ceil(n)-.5,h,i)}this._bIsPainted=!0},e.prototype.makeImage=function(){this._bIsPainted&&d.call(this,a)},e.prototype.isPainted=function(){return this._bIsPainted},e.prototype.clear=function(){this._oContext.clearRect(0,0,this._elCanvas.width,this._elCanvas.height),this._bIsPainted=!1},e.prototype.round=function(a){return a?Math.floor(1e3*a)/1e3:a},e}():function(){var a=function(a,b){this._el=a,this._htOption=b};return a.prototype.draw=function(a){for(var b=this._htOption,c=this._el,d=a.getModuleCount(),e=Math.floor(b.width/d),f=Math.floor(b.height/d),g=[''],h=0;d>h;h++){g.push("");for(var i=0;d>i;i++)g.push('');g.push("")}g.push("
"),c.innerHTML=g.join("");var j=c.childNodes[0],k=(b.width-j.offsetWidth)/2,l=(b.height-j.offsetHeight)/2;k>0&&l>0&&(j.style.margin=l+"px "+k+"px")},a.prototype.clear=function(){this._el.innerHTML=""},a}();QRCode=function(a,b){if(this._htOption={width:256,height:256,typeNumber:4,colorDark:"#000000",colorLight:"#ffffff",correctLevel:d.H},"string"==typeof b&&(b={text:b}),b)for(var c in b)this._htOption[c]=b[c];"string"==typeof a&&(a=document.getElementById(a)),this._android=n(),this._el=a,this._oQRCode=null,this._oDrawing=new q(this._el,this._htOption),this._htOption.text&&this.makeCode(this._htOption.text)},QRCode.prototype.makeCode=function(a){this._oQRCode=new b(r(a,this._htOption.correctLevel),this._htOption.correctLevel),this._oQRCode.addData(a),this._oQRCode.make(),this._el.title=a,this._oDrawing.draw(this._oQRCode),this.makeImage()},QRCode.prototype.makeImage=function(){"function"==typeof this._oDrawing.makeImage&&(!this._android||this._android>=3)&&this._oDrawing.makeImage()},QRCode.prototype.clear=function(){this._oDrawing.clear()},QRCode.CorrectLevel=d}(); From 151b6390615dd878421f20cf3cafacf6cc3dc919 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Sun, 31 Oct 2021 22:20:59 +0800 Subject: [PATCH 017/132] Update apps.json Use conventional data filename. --- apps.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps.json b/apps.json index 7d6057df5..18fec8eea 100644 --- a/apps.json +++ b/apps.json @@ -4199,6 +4199,6 @@ {"name":"authentiwatch.app.js","url":"app.js"}, {"name":"authentiwatch.img","url":"app-icon.js","evaluate":true} ], - "data": [{"name":"authentiwatch.tokens.json"}] + "data": [{"name":"authentiwatch.json"}] } ] From 066eb28760e78458bf2938dbb034685a55de5727 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Mon, 1 Nov 2021 10:07:45 +0800 Subject: [PATCH 018/132] Update interface.html Switch to Espruino Core copy of QRCode generator. --- apps/authentiwatch/interface.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/authentiwatch/interface.html b/apps/authentiwatch/interface.html index 255c5e4ca..201401a99 100644 --- a/apps/authentiwatch/interface.html +++ b/apps/authentiwatch/interface.html @@ -22,7 +22,7 @@ button{height:3em} - + + + From 3ed953fcd21b3234ecc182b9cc0a7d161b91f7cf Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Sat, 13 Nov 2021 00:58:50 +0800 Subject: [PATCH 032/132] Add HOTP support --- apps/authentiwatch/app.js | 72 ++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 19 deletions(-) diff --git a/apps/authentiwatch/app.js b/apps/authentiwatch/app.js index d5a8352cb..180035e14 100644 --- a/apps/authentiwatch/app.js +++ b/apps/authentiwatch/app.js @@ -10,7 +10,7 @@ const algos = { var tokens = require("Storage").readJSON("authentiwatch.json", true) || [ {algorithm:"SHA512",digits:8,period:60,secret:"aaaa aaaa aaaa aaaa",label:"AgAgAg"}, {algorithm:"SHA1",digits:6,period:30,secret:"bbbb bbbb bbbb bbbb",label:"BgBgBg"}, - {algorithm:"SHA1",digits:6,period:30,secret:"cccc cccc cccc cccc",label:"CgCgCg"}, + {algorithm:"SHA1",digits:6,period:-30,secret:"cccc cccc cccc cccc",label:"CgCgCg"}, {algorithm:"SHA1",digits:6,period:60,secret:"yyyy yyyy yyyy yyyy",label:"YgYgYg"}, {algorithm:"SHA1",digits:8,period:30,secret:"zzzz zzzz zzzz zzzz",label:"ZgZgZg"}, ]; @@ -72,21 +72,27 @@ function do_hmac(key, message, algo) { var v = new DataView(ret, ret[ret.length - 1] & 0x0F, 4); return v.getUint32(0) & 0x7FFFFFFF; } -function hotp_timed(seed, digits, period, algo) { - // RFC6238 +function hotp(token) { + var tick; var d = new Date(); - var seconds = Math.floor(d.getTime() / 1000); - var tick = Math.floor(seconds / period); + if (token.period > 0) { + // RFC6238 - timed + var seconds = Math.floor(d.getTime() / 1000); + tick = Math.floor(seconds / token.period); + } else { + // RFC4226 - counter + tick = -token.period; + } var msg = new Uint8Array(8); var v = new DataView(msg.buffer); v.setUint32(0, tick >> 16 >> 16); v.setUint32(4, tick & 0xFFFFFFFF); - var hash = do_hmac(b32decode(seed), msg, algo.toUpperCase()); - var ret = "" + hash % Math.pow(10, digits); - while (ret.length < digits) { + var hash = do_hmac(b32decode(token.secret), msg, token.algorithm.toUpperCase()); + var ret = "" + hash % Math.pow(10, token.digits); + while (ret.length < token.digits) { ret = "0" + ret; } - return {hotp:ret, next:(tick + 1) * period * 1000}; + return {hotp:ret, next:((token.period > 0) ? ((tick + 1) * token.period * 1000) : d.getTime() + 30000)}; } var state = { @@ -94,7 +100,8 @@ var state = { curtoken:-1, nextTime:0, otp:"", - rem:0 + rem:0, + hide:0 }; function drawToken(id, r) { @@ -143,17 +150,28 @@ function drawToken(id, r) { } function draw() { + var d = new Date(); if (state.curtoken != -1) { var t = tokens[state.curtoken]; - var d = new Date(); if (d.getTime() > state.nextTime) { - try { - var r = hotp_timed(t.secret, t.digits, t.period, t.algorithm); - state.nextTime = r.next; - state.otp = r.hotp; - } catch (err) { + if (state.hide == 0) { + // auto-hide the current token + state.curtoken = -1; state.nextTime = 0; - state.otp = "Not supported"; + } else { + // time to generate a new token + try { + var r = hotp(t); + state.nextTime = r.next; + state.otp = r.hotp; + if (t.period <= 0) { + state.hide = 1; + } + } catch (err) { + state.nextTime = 0; + state.otp = "Not supported"; + } + state.hide--; } } state.rem = Math.max(0, Math.floor((state.nextTime - d.getTime()) / 1000)); @@ -164,17 +182,25 @@ function draw() { var y = id * tokenentryheight + Bangle.appRect.y - state.listy; while (id < tokens.length && y < Bangle.appRect.y2) { drawToken(id, {x:Bangle.appRect.x, y:y, w:Bangle.appRect.w, h:tokenentryheight}); - if (id == state.curtoken && state.nextTime != 0) { + if (id == state.curtoken && (tokens[id].period <= 0 || state.nextTime != 0)) { drewcur = true; } id += 1; y += tokenentryheight; } if (drewcur) { + // the current token has been drawn - draw it again in 1sec if (state.drawtimer) { clearTimeout(state.drawtimer); } - state.drawtimer = setTimeout(draw, 1000); + state.drawtimer = setTimeout(draw, (tokens[state.curtoken].period > 0) ? 1000 : state.nexttime - d.getTime()); + if (tokens[state.curtoken].period <= 0) { + state.hide = 0; + } + } else { + // de-select the current token if it is scrolled out of view + state.curtoken = -1; + state.nexttime = 0; } } else { g.setFont("Vector", 30); @@ -202,6 +228,7 @@ function onTouch(zone, e) { } state.nextTime = 0; state.curtoken = id; + state.hide = 2; draw(); } } @@ -221,6 +248,13 @@ function onSwipe(e) { if (e == 1) { Bangle.showLauncher(); } + if (e == -1 && state.curtoken != -1 && tokens[state.curtoken].period <= 0) { + tokens[state.curtoken].period--; + require("Storage").writeJSON("authentiwatch.json", tokens); + state.nextTime = 0; + state.hide = 2; + draw(); + } } Bangle.on('touch', onTouch); From 1b9bc2a8c2df73a52586a852815f6158d020bb1d Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Sat, 13 Nov 2021 00:59:34 +0800 Subject: [PATCH 033/132] Add HOTP support --- apps/authentiwatch/interface.html | 67 +++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 12 deletions(-) diff --git a/apps/authentiwatch/interface.html b/apps/authentiwatch/interface.html index 823047d8b..b0ac7de45 100644 --- a/apps/authentiwatch/interface.html +++ b/apps/authentiwatch/interface.html @@ -19,6 +19,7 @@ body.select div#tokens,body.editing div#edit,body.scanning div#scan,body.showqr #edittoken.showadv #advbtn button:before,#edittoken.showadv #advbtn button:after{content:"\25b2"} button{height:3em} table button{width:100%} +form.totp tr.hotp,form.hotp tr.totp{display:none} @@ -30,7 +31,9 @@ table button{width:100%}