diff --git a/BUILD.md b/BUILD.md index b58514d..a88e083 100644 --- a/BUILD.md +++ b/BUILD.md @@ -7,7 +7,7 @@ ## Step-by-Step Build Instructions 1. Install dependencies: ```bash - npm install + npm ci ``` 2. Build the Firefox extension: diff --git a/chunked.js b/chunked.js new file mode 100644 index 0000000..6f26023 --- /dev/null +++ b/chunked.js @@ -0,0 +1,34 @@ +import zwus from 'zwus'; + +const SIZE = 65536; + +function encode(values, base, method) { + const parts = []; + for (let start = 0; start < values.length;) { + let end = Math.min(start + SIZE, values.length); + if (typeof values === 'string' && end < values.length && + values.charCodeAt(end - 1) >= 0xD800 && values.charCodeAt(end - 1) <= 0xDBFF) end--; + parts.push(zwus[method](values.slice(start, end), base)); + start = end; + } + return parts.join(zwus[base].unifier); +} + +function decode(text, base, method) { + const parts = [], sep = zwus[base].unifier; + for (let start = 0; start < text.length;) { + let end = Math.min(start + SIZE, text.length); + if (end < text.length) { + const cut = text.lastIndexOf(sep, end - 1); + end = cut >= start ? cut + 1 : (text.indexOf(sep, end) + 1 || text.length); + } + parts.push(zwus[method](text.slice(start, end), base)); + start = end; + } + return method === 'decodeToString' ? parts.join('') : parts.flat(); +} + +export const encodeString = (text, base) => encode(text, base, 'encodeString'); +export const encodeNumberArray = (numbers, base) => encode(numbers, base, 'encodeNumberArray'); +export const decodeToString = (text, base) => decode(text, base, 'decodeToString'); +export const decodeToNumberArray = (text, base) => decode(text, base, 'decodeToNumberArray'); diff --git a/dash.js b/dash.js index bc36ba7..586f43d 100644 --- a/dash.js +++ b/dash.js @@ -1,4 +1,4 @@ -import zwus from 'zwus'; +import * as chunked from './chunked.js'; import * as speck48_96ctr from './speck48_96ctr.js'; import * as speck32_64ecb from './speck32_64ecb.js'; import { makeSig, parseSig } from './sig.js'; @@ -8,6 +8,9 @@ const encoderDropdown = document.getElementById('encoder'); const cipherDropdown = document.getElementById('cipher'); const signBtn = document.getElementById('sign'); const sigDetect = document.getElementById('sigDetect'); +const notice = document.getElementById('notice'); +const buttons = ['encodeButton', 'decodeButton'].map(id => document.getElementById(id)); +const controls = [...buttons, encoderDropdown, cipherDropdown, signBtn]; document.getElementById('encodeButton').addEventListener('click', ACT); document.getElementById('decodeButton').addEventListener('click', ACT); @@ -15,9 +18,10 @@ signBtn.addEventListener('click', e => e.target.classList.toggle('on') ); -let fadeTimer; +let fadeTimer, busy = false; -function ACT(event) { +async function ACT(event) { + if (busy) return; clearTimeout(fadeTimer); sigDetect.className = ''; @@ -57,20 +61,47 @@ function ACT(event) { if (needsKey && !kStr) return; + busy = true; + controls.forEach(control => control.disabled = true); + notice.textContent = 'Processing…'; try { - let val = DESCRY[op][cipher](text, base, kStr); + let val = await DESCRY[op][cipher](text, base, kStr); if (op === 'NO' && signBtn.classList.contains('on')) val = makeSig(base, cipher) + val; textarea.value = val; + if (op === 'NO') { + notice.textContent = 'Copying…'; + const copied = await copyText(val); + if (copied && val.length <= 65536) + textarea.value = 'Copied to your clipboard.\n A copy has been placed between these brackets [' + val + ']'; + notice.textContent = copied ? `Copied ${val.length.toLocaleString()} characters.` : + 'Copy failed. The encoded text is in the box; select and copy it manually.'; + } else notice.textContent = `Decoded ${val.length.toLocaleString()} characters.`; } catch (e) { - console.log(e); + console.error(e); + notice.textContent = `Could not ${op === 'NO' ? 'encode' : 'decode'}: ${e.message}`; + } finally { + busy = false; + controls.forEach(control => control.disabled = false); } +} - if (op === 'NO') { - textarea.select(); - document.execCommand('copy'); - textarea.value = 'Copied to your clipboard.\n A copy has been placed between these brackets [' + textarea.value + ']'; +async function copyText(val) { + if (navigator.clipboard?.writeText) { + let timer; + try { + await Promise.race([ + navigator.clipboard.writeText(val), + new Promise((_, reject) => timer = setTimeout(() => reject(new Error('Copy timed out')), 5000)) + ]); + return true; + } catch (e) { console.warn('Clipboard copy failed', e); } + finally { clearTimeout(timer); } } + if (val.length > 65536) return false; + textarea.select(); + try { return document.execCommand('copy'); } + catch (e) { console.warn('Clipboard copy failed', e); return false; } } function getCipherKey() { @@ -80,18 +111,18 @@ function getCipherKey() { const DESCRY = { NO: { PLAIN: (ptStr, base) => - zwus.encodeString(ptStr, base), + chunked.encodeString(ptStr, base), SPECK48_96CTR: (ptStr, base, kStr) => - zwus.encodeNumberArray(speck48_96ctr.encrypt(ptStr, speck48_96ctr.getKey(kStr)), base), + chunked.encodeNumberArray(speck48_96ctr.encrypt(ptStr, speck48_96ctr.getKey(kStr)), base), 'SPECK32_64ECB (insecure)': (ptStr, base, kStr) => - zwus.encodeNumberArray(speck32_64ecb.encrypt(ptStr, speck32_64ecb.getKey(kStr)), base), + chunked.encodeNumberArray(speck32_64ecb.encrypt(ptStr, speck32_64ecb.getKey(kStr)), base), }, YES: { PLAIN: (ptStr, base) => - zwus.decodeToString(ptStr, base), - SPECK48_96CTR: (ptStr, base, kStr) => - speck48_96ctr.decrypt(zwus.decodeToNumberArray(ptStr, base), speck48_96ctr.getKey(kStr)), - 'SPECK32_64ECB (insecure)': (ptStr, base, kStr) => - speck32_64ecb.decrypt(zwus.decodeToNumberArray(ptStr, base), speck32_64ecb.getKey(kStr)), + chunked.decodeToString(ptStr, base), + SPECK48_96CTR: async (ptStr, base, kStr) => + speck48_96ctr.decrypt(await chunked.decodeToNumberArray(ptStr, base), speck48_96ctr.getKey(kStr)), + 'SPECK32_64ECB (insecure)': async (ptStr, base, kStr) => + speck32_64ecb.decrypt(await chunked.decodeToNumberArray(ptStr, base), speck32_64ecb.getKey(kStr)), } }; diff --git a/dist/chrome/content.js b/dist/chrome/content.js index 843b15b..6f63110 100644 --- a/dist/chrome/content.js +++ b/dist/chrome/content.js @@ -1,6 +1,6 @@ -(function(){"use strict";const I={3:{unifier:"­",0:"᠎",1:"​",2:"‍"},6:{unifier:"‌",0:"‍",1:"‏",2:"­",3:"⁠",4:"​",5:"‎"},8:{unifier:"‌",0:"‍",1:"‏",2:"­",3:"⁠",4:"​",5:"‎",6:"᠎",7:"\uFEFF"},encodeString:(s,e=3)=>Array.from(s,a=>a.codePointAt(0).toString(e).split("").map(p=>I[e][p]).join("")).join(I[e].unifier),encodeNumberArray:(s,e=3)=>s.map(a=>a.toString(e).split("").map(p=>I[e][p]).join("")).join(I[e].unifier),decodeToString:(s,e=3)=>s.split(I[e].unifier).map(a=>String.fromCodePoint(parseInt(Array.from(a).map(p=>Object.keys(I[e]).find(b=>I[e][b]===p)).join(""),e))).join(""),decodeToNumberArray:(s,e=3)=>s.split(I[e].unifier).map(a=>parseInt(Array.from(a).map(p=>Object.keys(I[e]).find(b=>I[e][b]===p)).join(""),e))};function J(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}var N,H;function Q(){if(H)return N;H=1;function s(e={}){const a=e.bits||16,p=e.rounds||22,b=e.rightRotations||7,d=e.leftRotations||2,l=2**a,o=l-1,i=(c,n)=>c>>n|c<c<>a-n,g=(c,n,t)=>(c=i(c,b),c=c+n&o,c^=t,n=h(n,d),n^=c,[c,n]),y=(c,n,t)=>(n^=c,n=i(n,d),c^=t,c=c-n&o,c=h(c,b),[c,n]);function E(c,n){let t=c[0],u=c[1],r=n[0],m=n.slice(1);[u,t]=g(u,t,r);for(let w=0;w{const u=c([n/l|0,n&o],t);return u[0]*l+u[1]}}return{encrypt:f(E),decrypt:f(A),encryptRaw:E,decryptRaw:A}}return N=s,N}var Z=Q();const L=J(Z);var D,M;function z(){if(M)return D;M=1;const s="Input must be an string, Buffer or Uint8Array";function e(l){let o;if(l instanceof Uint8Array)o=l;else if(typeof l=="string")o=new TextEncoder().encode(l);else throw new Error(s);return o}function a(l){return Array.prototype.map.call(l,function(o){return(o<16?"0":"")+o.toString(16)}).join("")}function p(l){return(4294967296+l).toString(16).substring(1)}function b(l,o,i){let h=` -`+l+" = ";for(let g=0;g=4294967296&&w++,t[u]=m,t[u+1]=w}function a(t,u,r,m){let w=t[u]+r;r<0&&(w+=4294967296);let k=t[u+1]+m;w>=4294967296&&k++,t[u]=w,t[u+1]=k}function p(t,u){return t[u]^t[u+1]<<8^t[u+2]<<16^t[u+3]<<24}function b(t,u,r,m,w,k){const be=h[w],he=h[w+1],ge=h[k],me=h[k+1];e(i,t,u),a(i,t,be,he);let S=i[m]^i[t],T=i[m+1]^i[t+1];i[m]=T,i[m+1]=S,e(i,r,m),S=i[u]^i[r],T=i[u+1]^i[r+1],i[u]=S>>>24^T<<8,i[u+1]=T>>>24^S<<8,e(i,t,u),a(i,t,ge,me),S=i[m]^i[t],T=i[m+1]^i[t+1],i[m]=S>>>16^T<<16,i[m+1]=T>>>16^S<<16,e(i,r,m),S=i[u]^i[r],T=i[u+1]^i[r+1],i[u]=T>>>31^S<<1,i[u+1]=S>>>31^T<<1}const d=new Uint32Array([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),l=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3],o=new Uint8Array(l.map(function(t){return t*2})),i=new Uint32Array(32),h=new Uint32Array(32);function g(t,u){let r=0;for(r=0;r<16;r++)i[r]=t.h[r],i[r+16]=d[r];for(i[24]=i[24]^t.t,i[25]=i[25]^t.t/4294967296,u&&(i[28]=~i[28],i[29]=~i[29]),r=0;r<32;r++)h[r]=p(t.b,4*r);for(r=0;r<12;r++)b(0,8,16,24,o[r*16+0],o[r*16+1]),b(2,10,18,26,o[r*16+2],o[r*16+3]),b(4,12,20,28,o[r*16+4],o[r*16+5]),b(6,14,22,30,o[r*16+6],o[r*16+7]),b(0,10,20,30,o[r*16+8],o[r*16+9]),b(2,12,22,24,o[r*16+10],o[r*16+11]),b(4,14,16,26,o[r*16+12],o[r*16+13]),b(6,8,18,28,o[r*16+14],o[r*16+15]);for(r=0;r<16;r++)t.h[r]=t.h[r]^i[r]^i[r+16]}const y=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);function E(t,u,r,m){if(t===0||t>64)throw new Error("Illegal output length, expected 0 < length <= 64");if(u&&u.length>64)throw new Error("Illegal key, expected Uint8Array with 0 < length <= 64");if(r&&r.length!==16)throw new Error("Illegal salt, expected Uint8Array with length is 16");if(m&&m.length!==16)throw new Error("Illegal personal, expected Uint8Array with length is 16");const w={b:new Uint8Array(128),h:new Uint32Array(16),t:0,c:0,outlen:t};y.fill(0),y[0]=t,u&&(y[1]=u.length),y[2]=1,y[3]=1,r&&y.set(r,32),m&&y.set(m,48);for(let k=0;k<16;k++)w.h[k]=d[k]^p(y,k*4);return u&&(A(w,u),w.c=128),w}function A(t,u){for(let r=0;r>2]>>8*(r&3);return u}function c(t,u,r,m,w){r=r||64,t=s.normalizeInput(t),m&&(m=s.normalizeInput(m)),w&&(w=s.normalizeInput(w));const k=E(r,u,m,w);return A(k,t),f(k)}function n(t,u,r,m,w){const k=c(t,u,r,m,w);return s.toHex(k)}return U={blake2b:c,blake2bHex:n,blake2bInit:E,blake2bUpdate:A,blake2bFinal:f},U}var B,q;function te(){if(q)return B;q=1;const s=z();function e(f,c){return f[c]^f[c+1]<<8^f[c+2]<<16^f[c+3]<<24}function a(f,c,n,t,u,r){l[f]=l[f]+l[c]+u,l[t]=p(l[t]^l[f],16),l[n]=l[n]+l[t],l[c]=p(l[c]^l[n],12),l[f]=l[f]+l[c]+r,l[t]=p(l[t]^l[f],8),l[n]=l[n]+l[t],l[c]=p(l[c]^l[n],7)}function p(f,c){return f>>>c^f<<32-c}const b=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),d=new Uint8Array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0]),l=new Uint32Array(16),o=new Uint32Array(16);function i(f,c){let n=0;for(n=0;n<8;n++)l[n]=f.h[n],l[n+8]=b[n];for(l[12]^=f.t,l[13]^=f.t/4294967296,c&&(l[14]=~l[14]),n=0;n<16;n++)o[n]=e(f.b,4*n);for(n=0;n<10;n++)a(0,4,8,12,o[d[n*16+0]],o[d[n*16+1]]),a(1,5,9,13,o[d[n*16+2]],o[d[n*16+3]]),a(2,6,10,14,o[d[n*16+4]],o[d[n*16+5]]),a(3,7,11,15,o[d[n*16+6]],o[d[n*16+7]]),a(0,5,10,15,o[d[n*16+8]],o[d[n*16+9]]),a(1,6,11,12,o[d[n*16+10]],o[d[n*16+11]]),a(2,7,8,13,o[d[n*16+12]],o[d[n*16+13]]),a(3,4,9,14,o[d[n*16+14]],o[d[n*16+15]]);for(n=0;n<8;n++)f.h[n]^=l[n]^l[n+8]}function h(f,c){if(!(f>0&&f<=32))throw new Error("Incorrect output length, should be in [1, 32]");const n=c?c.length:0;if(c&&!(n>0&&n<=32))throw new Error("Incorrect key length, should be in [1, 32]");const t={h:new Uint32Array(b),b:new Uint8Array(64),c:0,t:0,outlen:f};return t.h[0]^=16842752^n<<8^f,n>0&&(g(t,c),t.c=64),t}function g(f,c){for(let n=0;n>2]>>8*(n&3)&255;return c}function E(f,c,n){n=n||32,f=s.normalizeInput(f);const t=h(n,c);return g(t,f),y(t)}function A(f,c,n){const t=E(f,c,n);return s.toHex(t)}return B={blake2s:E,blake2sHex:A,blake2sInit:h,blake2sUpdate:g,blake2sFinal:y},B}var _,V;function ne(){if(V)return _;V=1;const s=ee(),e=te();return _={blake2b:s.blake2b,blake2bHex:s.blake2bHex,blake2bInit:s.blake2bInit,blake2bUpdate:s.blake2bUpdate,blake2bFinal:s.blake2bFinal,blake2s:e.blake2s,blake2sHex:e.blake2sHex,blake2sInit:e.blake2sInit,blake2sUpdate:e.blake2sUpdate,blake2sFinal:e.blake2sFinal},_}var W=ne();const re=L({bits:24,rounds:23,rightRotations:8,leftRotations:3});function oe(s){const e=W.blake2bHex(s,null,12);return[parseInt(e.slice(0,6),16),parseInt(e.slice(6,12),16),parseInt(e.slice(12,18),16),parseInt(e.slice(18,24),16)]}function ie(s,e){if(!s||s.length===0)return"";const a=s[0];return s.slice(1).map((b,d)=>{const l=a*16777216+(d&16777215),o=re.encrypt(l,e),i=(b^o)>>>0;try{return String.fromCodePoint(i)}catch{return""}}).join("")}const se=L();function le(s){const e=W.blake2bHex(s,null,8);return[parseInt(e.slice(0,4),16),parseInt(e.slice(4,8),16),parseInt(e.slice(8,12),16),parseInt(e.slice(12,16),16)]}function ce(s,e){return s.map(a=>{try{return String.fromCodePoint(se.decrypt(a,e))}catch{return""}}).join("")}const O="‍​­",x={3:"‍​­᠎‍",6:"‍​­‌‍",8:"‍​­‌‌"},X={1:"SPECK48_96CTR",2:"SPECK32_64ECB (insecure)"};Object.fromEntries(Object.entries(X).map(([s,e])=>[e,+s]));function ae(s){if(!s.includes(O))return null;const e=Object.keys(x).find(d=>s.includes(x[d]));if(!e)return null;const a=s.indexOf(x[e]),p=s.slice(a+x[e].length),b=I[e].unifier+I[e][0];if(p.startsWith(b)){const l=Array.from(p.slice(b.length,b.length+3)).map(g=>Object.keys(I[e]).find(y=>I[e][y]===g)).join(""),o=X[parseInt(l,e)],i=p.slice(b.length+3),h=x[e].length+b.length+3;return{base:e,cipher:o,payload:i,sigIdx:a,sigLen:h}}return{base:e,cipher:"PLAIN",payload:p,sigIdx:a,sigLen:x[e].length}}function K(s,e,a){const p=new Set(Object.values(I[e]));let b=a;for(;bArray.from(n,l=>(+e==7?ee(l):l.codePointAt(0)).toString(e).split("").map(p=>A[e][p]).join("")).join(A[e].unifier),encodeNumberArray:(n,e=7)=>n.map(l=>l.toString(e).split("").map(p=>A[e][p]).join("")).join(A[e].unifier),decodeToString:(n,e=7)=>A.decodeToNumberArray(n,e).map(l=>String.fromCodePoint(+e==7?te(l):l)).join(""),decodeToNumberArray:(n,e=7)=>n.split(A[e].unifier).map(l=>Array.from(l).map(p=>Object.keys(A[e]).find(b=>A[e][b]===p)).join("")).filter(Boolean).map(l=>parseInt(l,e))},Q="te aoinshrdlucmfwypvbgkjqxz.,!?'-:;()0123456789ETAOINSHRDLUCMFWYPVBGKJQXZ",H=[...new Set([...Q,...Array.from({length:95},(n,e)=>String.fromCharCode(e+32))])],Z=new Map(H.map((n,e)=>[n,e])),ee=n=>Z.get(n)??(n.codePointAt(0)<32?n.codePointAt(0)+95:n.codePointAt(0)),te=n=>n<95?H[n].codePointAt(0):n<127?n-95:n;function ne(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var D,L;function oe(){if(L)return D;L=1;function n(e={}){const l=e.bits||16,p=e.rounds||22,b=e.rightRotations||7,d=e.leftRotations||2,c=2**l,i=c-1,s=(a,o)=>a>>o|a<a<>l-o,g=(a,o,t)=>(a=s(a,b),a=a+o&i,a^=t,o=h(o,d),o^=a,[a,o]),y=(a,o,t)=>(o^=a,o=s(o,d),a^=t,a=a-o&i,a=h(a,b),[a,o]);function k(a,o){let t=a[0],u=a[1],r=o[0],m=o.slice(1);[u,t]=g(u,t,r);for(let w=0;w{const u=a([o/c|0,o&i],t);return u[0]*c+u[1]}}return{encrypt:f(k),decrypt:f(I),encryptRaw:k,decryptRaw:I}}return D=n,D}var re=oe();const M=ne(re);var U,z;function G(){if(z)return U;z=1;const n="Input must be an string, Buffer or Uint8Array";function e(c){let i;if(c instanceof Uint8Array)i=c;else if(typeof c=="string")i=new TextEncoder().encode(c);else throw new Error(n);return i}function l(c){return Array.prototype.map.call(c,function(i){return(i<16?"0":"")+i.toString(16)}).join("")}function p(c){return(4294967296+c).toString(16).substring(1)}function b(c,i,s){let h=` +`+c+" = ";for(let g=0;g=4294967296&&w++,t[u]=m,t[u+1]=w}function l(t,u,r,m){let w=t[u]+r;r<0&&(w+=4294967296);let E=t[u+1]+m;w>=4294967296&&E++,t[u]=w,t[u+1]=E}function p(t,u){return t[u]^t[u+1]<<8^t[u+2]<<16^t[u+3]<<24}function b(t,u,r,m,w,E){const ye=h[w],Ee=h[w+1],ke=h[E],Ae=h[E+1];e(s,t,u),l(s,t,ye,Ee);let S=s[m]^s[t],T=s[m+1]^s[t+1];s[m]=T,s[m+1]=S,e(s,r,m),S=s[u]^s[r],T=s[u+1]^s[r+1],s[u]=S>>>24^T<<8,s[u+1]=T>>>24^S<<8,e(s,t,u),l(s,t,ke,Ae),S=s[m]^s[t],T=s[m+1]^s[t+1],s[m]=S>>>16^T<<16,s[m+1]=T>>>16^S<<16,e(s,r,m),S=s[u]^s[r],T=s[u+1]^s[r+1],s[u]=T>>>31^S<<1,s[u+1]=S>>>31^T<<1}const d=new Uint32Array([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),c=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3],i=new Uint8Array(c.map(function(t){return t*2})),s=new Uint32Array(32),h=new Uint32Array(32);function g(t,u){let r=0;for(r=0;r<16;r++)s[r]=t.h[r],s[r+16]=d[r];for(s[24]=s[24]^t.t,s[25]=s[25]^t.t/4294967296,u&&(s[28]=~s[28],s[29]=~s[29]),r=0;r<32;r++)h[r]=p(t.b,4*r);for(r=0;r<12;r++)b(0,8,16,24,i[r*16+0],i[r*16+1]),b(2,10,18,26,i[r*16+2],i[r*16+3]),b(4,12,20,28,i[r*16+4],i[r*16+5]),b(6,14,22,30,i[r*16+6],i[r*16+7]),b(0,10,20,30,i[r*16+8],i[r*16+9]),b(2,12,22,24,i[r*16+10],i[r*16+11]),b(4,14,16,26,i[r*16+12],i[r*16+13]),b(6,8,18,28,i[r*16+14],i[r*16+15]);for(r=0;r<16;r++)t.h[r]=t.h[r]^s[r]^s[r+16]}const y=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);function k(t,u,r,m){if(t===0||t>64)throw new Error("Illegal output length, expected 0 < length <= 64");if(u&&u.length>64)throw new Error("Illegal key, expected Uint8Array with 0 < length <= 64");if(r&&r.length!==16)throw new Error("Illegal salt, expected Uint8Array with length is 16");if(m&&m.length!==16)throw new Error("Illegal personal, expected Uint8Array with length is 16");const w={b:new Uint8Array(128),h:new Uint32Array(16),t:0,c:0,outlen:t};y.fill(0),y[0]=t,u&&(y[1]=u.length),y[2]=1,y[3]=1,r&&y.set(r,32),m&&y.set(m,48);for(let E=0;E<16;E++)w.h[E]=d[E]^p(y,E*4);return u&&(I(w,u),w.c=128),w}function I(t,u){for(let r=0;r>2]>>8*(r&3);return u}function a(t,u,r,m,w){r=r||64,t=n.normalizeInput(t),m&&(m=n.normalizeInput(m)),w&&(w=n.normalizeInput(w));const E=k(r,u,m,w);return I(E,t),f(E)}function o(t,u,r,m,w){const E=a(t,u,r,m,w);return n.toHex(E)}return B={blake2b:a,blake2bHex:o,blake2bInit:k,blake2bUpdate:I,blake2bFinal:f},B}var O,V;function se(){if(V)return O;V=1;const n=G();function e(f,a){return f[a]^f[a+1]<<8^f[a+2]<<16^f[a+3]<<24}function l(f,a,o,t,u,r){c[f]=c[f]+c[a]+u,c[t]=p(c[t]^c[f],16),c[o]=c[o]+c[t],c[a]=p(c[a]^c[o],12),c[f]=c[f]+c[a]+r,c[t]=p(c[t]^c[f],8),c[o]=c[o]+c[t],c[a]=p(c[a]^c[o],7)}function p(f,a){return f>>>a^f<<32-a}const b=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),d=new Uint8Array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0]),c=new Uint32Array(16),i=new Uint32Array(16);function s(f,a){let o=0;for(o=0;o<8;o++)c[o]=f.h[o],c[o+8]=b[o];for(c[12]^=f.t,c[13]^=f.t/4294967296,a&&(c[14]=~c[14]),o=0;o<16;o++)i[o]=e(f.b,4*o);for(o=0;o<10;o++)l(0,4,8,12,i[d[o*16+0]],i[d[o*16+1]]),l(1,5,9,13,i[d[o*16+2]],i[d[o*16+3]]),l(2,6,10,14,i[d[o*16+4]],i[d[o*16+5]]),l(3,7,11,15,i[d[o*16+6]],i[d[o*16+7]]),l(0,5,10,15,i[d[o*16+8]],i[d[o*16+9]]),l(1,6,11,12,i[d[o*16+10]],i[d[o*16+11]]),l(2,7,8,13,i[d[o*16+12]],i[d[o*16+13]]),l(3,4,9,14,i[d[o*16+14]],i[d[o*16+15]]);for(o=0;o<8;o++)f.h[o]^=c[o]^c[o+8]}function h(f,a){if(!(f>0&&f<=32))throw new Error("Incorrect output length, should be in [1, 32]");const o=a?a.length:0;if(a&&!(o>0&&o<=32))throw new Error("Incorrect key length, should be in [1, 32]");const t={h:new Uint32Array(b),b:new Uint8Array(64),c:0,t:0,outlen:f};return t.h[0]^=16842752^o<<8^f,o>0&&(g(t,a),t.c=64),t}function g(f,a){for(let o=0;o>2]>>8*(o&3)&255;return a}function k(f,a,o){o=o||32,f=n.normalizeInput(f);const t=h(o,a);return g(t,f),y(t)}function I(f,a,o){const t=k(f,a,o);return n.toHex(t)}return O={blake2s:k,blake2sHex:I,blake2sInit:h,blake2sUpdate:g,blake2sFinal:y},O}var _,W;function le(){if(W)return _;W=1;const n=ie(),e=se();return _={blake2b:n.blake2b,blake2bHex:n.blake2bHex,blake2bInit:n.blake2bInit,blake2bUpdate:n.blake2bUpdate,blake2bFinal:n.blake2bFinal,blake2s:e.blake2s,blake2sHex:e.blake2sHex,blake2sInit:e.blake2sInit,blake2sUpdate:e.blake2sUpdate,blake2sFinal:e.blake2sFinal},_}var X=le();const ce=M({bits:24,rounds:23,rightRotations:8,leftRotations:3});function ae(n){const e=X.blake2bHex(n,null,12);return[parseInt(e.slice(0,6),16),parseInt(e.slice(6,12),16),parseInt(e.slice(12,18),16),parseInt(e.slice(18,24),16)]}function ue(n,e){if(!n||n.length===0)return"";const l=n[0];return n.slice(1).map((b,d)=>{const c=l*16777216+(d&16777215),i=ce.encrypt(c,e),s=(b^i)>>>0;try{return String.fromCodePoint(s)}catch{return""}}).join("")}const fe=M();function de(n){const e=X.blake2bHex(n,null,8);return[parseInt(e.slice(0,4),16),parseInt(e.slice(4,8),16),parseInt(e.slice(8,12),16),parseInt(e.slice(12,16),16)]}function pe(n,e){return n.map(l=>{try{return String.fromCodePoint(fe.decrypt(l,e))}catch{return""}}).join("")}const N="‍​­",x={3:"‍​­᠎‍",6:"‍​­‌‍",7:"‍​­‌‌"},K={1:"SPECK48_96CTR",2:"SPECK32_64ECB (insecure)"};Object.fromEntries(Object.entries(K).map(([n,e])=>[e,+n]));function be(n){let e=n.indexOf(N),l;for(;e!==-1&&(l=Object.keys(x).find(d=>n.startsWith(x[d],e)),!l);)e=n.indexOf(N,e+N.length);if(!l)return null;const p=n.slice(e+x[l].length),b=A[l].unifier+A[l][0];if(p.startsWith(b)){const c=Array.from(p.slice(b.length,b.length+3)).map(g=>Object.keys(A[l]).find(y=>A[l][y]===g)).join(""),i=K[parseInt(c,l)];if(!i)return{base:l,cipher:"PLAIN",payload:p,sigIdx:e,sigLen:x[l].length};const s=p.slice(b.length+3),h=x[l].length+b.length+3;return{base:l,cipher:i,payload:s,sigIdx:e,sigLen:h}}return{base:l,cipher:"PLAIN",payload:p,sigIdx:e,sigLen:x[l].length}}function $(n,e,l){const p=new Set(Object.values(A[e]));let b=l;for(;bde(h,e),$(h)}function $(s){const{wrap:e,node:a,start:p,endNode:b,end:d}=s;if(!a.isConnected||!b.isConnected){e.remove(),C.delete(s);return}const l=a.parentElement;if(!l||l.checkVisibility&&!l.checkVisibility({checkOpacity:!0,checkVisibilityCSS:!0})){e.style.display="none";return}const o=document.createRange();try{o.setStart(a,p),o.setEnd(b,Math.min(d,b.nodeValue.length))}catch{e.remove(),C.delete(s);return}let i=o.getBoundingClientRect();if(!i.width&&!i.height&&(i=l.getBoundingClientRect()),!i.width&&!i.height){e.style.display="none";return}if(i.bottom<0||i.top>window.innerHeight||i.right<0||i.left>window.innerWidth){e.style.display="none";return}let h=l;for(;h&&h!==document.body&&h!==document.documentElement;){const E=window.getComputedStyle(h);if(E.overflow!=="visible"||E.overflowX!=="visible"||E.overflowY!=="visible"){const A=h.getBoundingClientRect();if(i.bottomA.bottom||i.rightA.right){e.style.display="none";return}}h=h.parentElement}e.style.display="flex";const g=i.left+(i.width||0)/2,y=i.top;e.style.left=`${g-e.offsetWidth/2}px`,e.style.top=`${y-e.offsetHeight-2}px`}function de(s,e){const{wrap:a,node:p,start:b,endNode:d,end:l}=s,o=document.createRange();o.setStart(p,b),o.setEnd(d,l);const i=o.toString().slice(e.sigLen);let h="";if(e.cipher==="PLAIN")try{h=I.decodeToString(i,e.base)}catch(g){console.error(g)}else{const g=prompt(`inØsight: enter password (${e.cipher}):`);if(!g)return;try{const y=I.decodeToNumberArray(i,e.base);e.cipher==="SPECK48_96CTR"?h=ie(y,oe(g)):e.cipher==="SPECK32_64ECB (insecure)"&&(h=ce(y,le(g)))}catch(y){console.error(y)}if(!h){alert("Decryption failed.");return}}if(h){o.deleteContents();const g=document.createElement("span");g.className="inzerosight-decoded",g.style.color="#00b4d8",g.style.fontWeight="600",g.textContent=` ${h} `,o.insertNode(g),a.remove(),C.delete(s)}}function pe(s,e,a){let p=s,b=K(s.nodeValue,e,a);for(;b===p.nodeValue.length;){let d=p.nextSibling,l=!1;for(;(d==null?void 0:d.nodeType)===Node.ELEMENT_NODE&&d.tagName==="WBR";)l=!0,d=d.nextSibling;if(!l||(d==null?void 0:d.nodeType)!==Node.TEXT_NODE)break;const o=K(d.nodeValue,e,0);if(!o)break;p=d,b=o}return{endNode:p,end:b}}function j(s){if(!s||s.nodeType!==Node.TEXT_NODE)return;const e=s.nodeValue;if(!e||!e.includes(O))return;let a=0;for(;a{var d;return e[(d=b.parentElement)==null?void 0:d.tagName]?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}});let p;for(;p=a.nextNode();)j(p)}Y(document.body);let F;function P(){F||C.size===0||(F=requestAnimationFrame(()=>{F=null,C.forEach($)}))}new MutationObserver(s=>{var e;for(const a of[...C])(!a.node.isConnected||!((e=a.node.nodeValue)!=null&&e.startsWith(O,a.start)))&&(a.wrap.remove(),C.delete(a));for(const a of s)if(a.type==="characterData")j(a.target);else for(const p of a.addedNodes)p.nodeType===Node.TEXT_NODE?j(p):p.nodeType===Node.ELEMENT_NODE&&p.id!=="in0-host"&&Y(p);P()}).observe(document.documentElement,{childList:!0,subtree:!0,characterData:!0}),window.addEventListener("scroll",P,{capture:!0,passive:!0}),window.addEventListener("resize",P,{passive:!0})})(); + `,P.appendChild(n),(document.body||document.documentElement).appendChild(R)}function ge(n,e,l,p,b){for(const g of C)if(g.node===n&&g.start===l)return;he();const d=document.createElement("div");d.className="in0-wrap";const c=document.createElement("button");c.className="in0-btn",c.textContent=e.cipher==="PLAIN"?"Decode":"Decrypt";const i=document.createElement("span");i.className="in0-badge",i.textContent="Ø",c.appendChild(i);const s=document.createElement("div");s.className="in0-arrow",d.appendChild(c),d.appendChild(s),P.appendChild(d);const h={wrap:d,node:n,start:l,endNode:p,end:b};C.add(h),c.onclick=()=>me(h,e),Y(h)}function Y(n){const{wrap:e,node:l,start:p,endNode:b,end:d}=n;if(!l.isConnected||!b.isConnected){e.remove(),C.delete(n);return}const c=l.parentElement;if(!c||c.checkVisibility&&!c.checkVisibility({checkOpacity:!0,checkVisibilityCSS:!0})){e.style.display="none";return}const i=document.createRange();try{i.setStart(l,p),i.setEnd(b,Math.min(d,b.nodeValue.length))}catch{e.remove(),C.delete(n);return}let s=i.getBoundingClientRect();if(!s.width&&!s.height&&(s=c.getBoundingClientRect()),!s.width&&!s.height){e.style.display="none";return}if(s.bottom<0||s.top>window.innerHeight||s.right<0||s.left>window.innerWidth){e.style.display="none";return}let h=c;for(;h&&h!==document.body&&h!==document.documentElement;){const k=window.getComputedStyle(h);if(k.overflow!=="visible"||k.overflowX!=="visible"||k.overflowY!=="visible"){const I=h.getBoundingClientRect();if(s.bottomI.bottom||s.rightI.right){e.style.display="none";return}}h=h.parentElement}e.style.display="flex";const g=s.left+(s.width||0)/2,y=s.top;e.style.left=`${g-e.offsetWidth/2}px`,e.style.top=`${y-e.offsetHeight-2}px`}function me(n,e){const{wrap:l,node:p,start:b,endNode:d,end:c}=n,i=document.createRange();i.setStart(p,b),i.setEnd(d,c);const s=i.toString().slice(e.sigLen);let h="";if(e.cipher==="PLAIN")try{h=A.decodeToString(s,e.base)}catch(g){console.error(g)}else{const g=prompt(`inØsight: enter password (${e.cipher}):`);if(!g)return;try{const y=A.decodeToNumberArray(s,e.base);e.cipher==="SPECK48_96CTR"?h=ue(y,ae(g)):e.cipher==="SPECK32_64ECB (insecure)"&&(h=pe(y,de(g)))}catch(y){console.error(y)}if(!h){alert("Decryption failed.");return}}if(h){i.deleteContents();const g=document.createElement("span");g.className="inzerosight-decoded",g.style.color="#00b4d8",g.style.fontWeight="600",g.textContent=` ${h} `,i.insertNode(g),l.remove(),C.delete(n)}}function we(n,e,l){let p=n,b=$(n.nodeValue,e,l);for(;b===p.nodeValue.length;){let d=p.nextSibling,c=!1;for(;(d==null?void 0:d.nodeType)===Node.ELEMENT_NODE&&d.tagName==="WBR";)c=!0,d=d.nextSibling;if(!c||(d==null?void 0:d.nodeType)!==Node.TEXT_NODE)break;const i=$(d.nodeValue,e,0);if(!i)break;p=d,b=i}return{endNode:p,end:b}}function v(n){if(!n||n.nodeType!==Node.TEXT_NODE)return;const e=n.nodeValue;if(!e||!e.includes(N))return;let l=0;for(;l{var d;return e[(d=b.parentElement)==null?void 0:d.tagName]?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}});let p;for(;p=l.nextNode();)v(p)}J(document.body);let F;function j(){F||C.size===0||(F=requestAnimationFrame(()=>{F=null,C.forEach(Y)}))}new MutationObserver(n=>{var e;for(const l of[...C])(!l.node.isConnected||!((e=l.node.nodeValue)!=null&&e.startsWith(N,l.start)))&&(l.wrap.remove(),C.delete(l));for(const l of n)if(l.type==="characterData")v(l.target);else for(const p of l.addedNodes)p.nodeType===Node.TEXT_NODE?v(p):p.nodeType===Node.ELEMENT_NODE&&p.id!=="in0-host"&&J(p);j()}).observe(document.documentElement,{childList:!0,subtree:!0,characterData:!0}),window.addEventListener("scroll",j,{capture:!0,passive:!0}),window.addEventListener("resize",j,{passive:!0})})(); diff --git a/dist/chrome/index.html b/dist/chrome/index.html index 474b1b8..82bc1cf 100644 --- a/dist/chrome/index.html +++ b/dist/chrome/index.html @@ -7,15 +7,15 @@ -

inØsight 3.1.0source

+

inØsight 3.2.0source