From 90e8a3a850c42622114283ec35d7796ccbeb2ed5 Mon Sep 17 00:00:00 2001 From: Eric Bell Date: Tue, 1 Dec 2026 13:39:48 -0500 Subject: [PATCH] Add Masked print view: secrets shown with every digit hidden Co-Authored-By: Claude Sonnet 5.5 --- src/app.js | 2 ++ src/print.js | 15 +++++++++++---- src/version.js | 2 +- test/print.test.js | 13 +++++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/app.js b/src/app.js index f18af70..892fcba 100644 --- a/src/app.js +++ b/src/app.js @@ -859,6 +859,7 @@ if (mode === 'summary') return printSummary(state.doc); const doc = state.doc; const kept = mode === 'complete' ? 'This copy INCLUDES passwords, PINs and other secrets. Keep it locked away (fire safe or sealed envelope).' + : mode === 'obscured' ? 'This is the MASKED copy. Secrets are shown, but every digit in them is replaced by \u2022. Pictures marked secret are withheld. Keep it locked away.' : mode === 'lawyer' ? "This is the LAWYER'S VIEW. It includes account numbers and other details a lawyer needs, but the most private secrets (passwords, PINs, balances) are WITHHELD. Keep it locked away." : 'Secrets (passwords, PINs, security answers) are WITHHELD from this copy. They are stored in the encrypted file.'; const content = [ @@ -896,6 +897,7 @@ radio('masked', true, 'Withhold secrets (safe overview; ' + plural(n.lawyer + n.secret) + ' hidden)'), radio('lawyer', false, "Lawyer's view (shows " + n.lawyer + ' lawyer-level value' + (n.lawyer === 1 ? '' : 's') + '; ' + plural(n.secret) + ' hidden)'), radio('summary', false, "Lawyer's summary (a short list of " + sum.records + ' record' + (sum.records === 1 ? '' : 's') + ' with lawyer-level values, ' + sum.values + ' value' + (sum.values === 1 ? '' : 's') + ')'), + radio('obscured', false, 'Masked (shows ' + plural(n.lawyer + n.secret) + ' with every number hidden)'), radio('complete', false, 'Include secrets (full copy: store it securely)'), h('div', { class: 'row' }, btn('Cancel', () => { dlg.close(); dlg.remove(); }), diff --git a/src/print.js b/src/print.js index 4f73cdc..607f92a 100644 --- a/src/print.js +++ b/src/print.js @@ -8,7 +8,11 @@ import { printGroups } from './ops.js'; // rest withheld) and 'complete' (everything). A boolean is accepted for older // callers: true is 'complete', false is 'masked'. 'summary' is the lawyer's summary: // it shows lawyer-level values like 'lawyer' does, but lists only those records (see summaryGroups). -export const PRINT_MODES = ['masked', 'lawyer', 'complete', 'summary']; +// 'obscured' is the "Masked" view: like 'complete', but every digit in a secret value is replaced +// by a bullet, so the shape of an answer shows without the number. Pictures can't be masked, so a +// secret image (or a secret frame with a picture) is withheld. +export const PRINT_MODES = ['masked', 'lawyer', 'complete', 'summary', 'obscured']; +export const maskDigits = (text) => String(text == null ? '' : text).replace(/\p{Nd}/gu, '\u2022'); export function normalizeMode(mode) { if (mode === true) return 'complete'; return PRINT_MODES.includes(mode) ? mode : 'masked'; @@ -20,6 +24,7 @@ export function normalizeMode(mode) { export function isHidden(item, mode) { if (!item.secret) return false; const m = normalizeMode(mode); + if (m === 'obscured') return item.kind === 'image' || !!item.image; return m === 'complete' ? false : m === 'masked' ? true : !item.lawyer; } @@ -32,7 +37,8 @@ export function displayValue(field, mode) { } if (field.secret) { if (!field.value) return '(not set)'; - return isHidden(field, mode) ? '[withheld]' : field.value; + if (isHidden(field, mode)) return '[withheld]'; + return normalizeMode(mode) === 'obscured' ? maskDigits(field.value) : field.value; } return field.value || '(blank)'; } @@ -68,11 +74,12 @@ export function frameLayout(frame) { export function frameView(frame, mode) { const hasContent = !!(frame.image || String(frame.text || '').trim() || String(frame.ifStuck || '').trim()); const withheld = isHidden(frame, mode) && hasContent; + const m = frame.secret && normalizeMode(mode) === 'obscured' ? maskDigits : (x) => x; return { withheld, image: withheld ? '' : frame.image, - text: withheld ? '' : frame.text, - ifStuck: withheld ? '' : String(frame.ifStuck || '').trim(), + text: withheld ? '' : m(frame.text), + ifStuck: withheld ? '' : m(String(frame.ifStuck || '').trim()), stop: withheld ? false : !!frame.stop, layout: withheld ? 'none' : frameLayout(frame), }; diff --git a/src/version.js b/src/version.js index 46211bf..c403436 100644 --- a/src/version.js +++ b/src/version.js @@ -2,7 +2,7 @@ // YYMMDD is the date, X the iteration that day (A first, B second, ...). // Bump with `npm run bump` (see bump-version.js). build.js strips `export`. -export const APP_VERSION = '261127A'; +export const APP_VERSION = '261201A'; const VERSION_RE = /^(\d{6})([A-Z])$/; export const isVersion = (v) => typeof v === 'string' && VERSION_RE.test(v); diff --git a/test/print.test.js b/test/print.test.js index 335b48d..2e4e93d 100644 --- a/test/print.test.js +++ b/test/print.test.js @@ -158,3 +158,16 @@ test("the summary mode shows lawyer values like the lawyer's view and keeps plai assert.equal(isHidden(acct.num, 'summary'), false); assert.equal(isHidden(acct.amt, 'summary'), true); }); + +test('obscured ("Masked") view shows secrets with every digit replaced; images are withheld', () => { + const pin = { label: 'PIN', value: 'ab 1234-x9', secret: true }; + assert.equal(displayValue(pin, 'obscured'), 'ab ••••-x•'); + assert.equal(displayValue({ label: 'n', value: 'Ann 5', secret: false }, 'obscured'), 'Ann 5'); + assert.equal(displayValue({ label: 'p', value: '', secret: true }, 'obscured'), '(not set)'); + assert.equal(displayValue({ label: 'c', kind: 'image', value: 'data:x', secret: true }, 'obscured'), '[withheld]'); + const fr = frameView({ image: '', text: 'PIN 4321', ifStuck: 'call 555', layout: 'under', secret: true }, 'obscured'); + assert.equal(fr.withheld, false); + assert.equal(fr.text, 'PIN ••••'); + assert.equal(fr.ifStuck, 'call •••'); + assert.equal(frameView({ image: 'data:x', text: 't', layout: 'under', secret: true }, 'obscured').withheld, true); +});