1 · Derive stealth keys
+1 · Derive stealth keys
A wallet signs the canonical Wraith message; the 64-byte signature is split into two domain-separated seeds, and each seed expands into a key pair. The public halves form @@ -408,22 +475,23 @@
From a0aeb3f2ed0f794af68fa56543bdb8f36202d81b Mon Sep 17 00:00:00 2001
From: Moonwalker-rgb Run the full stealth payment flow client-side — no wallet, no network calls, nothing leaves your browser.
A wallet signs the canonical Wraith message; the 64-byte signature is split into two
domain-separated seeds, and each seed expands into a key pair. The public halves form
@@ -408,22 +475,23 @@ Wraith Stealth Playground
1 · Derive stealth keys
+ 1 · Derive stealth keys
1 · Derive stealth keys
Copy permalink — share the current step + inputs.
+ +
A fresh one-time ephemeral keypair is generated per payment. ECDH with the recipient's
viewing key derives the one-time stealth address, and the stealth-announcer
@@ -431,36 +499,40 @@
Copy permalink — share the current step + inputs.
+ +Announcements are filtered by view tag (a single byte rejects ~255/256 non-matches), then matched with ECDH + Ed25519 point addition. The batch below is parsed from the fixture @@ -468,42 +540,48 @@
No keys handy? Load the demo keys that match the fixture announcements.
+No keys handy?
Copy permalink — share the current step + inputs.
+
Only the recipient can spend from a stealth address: the stealth private scalar
(spendingScalar + hashToScalar(sharedSecret) mod L) signs the withdrawal.
@@ -511,16 +589,16 @@
Copy permalink — share the current step + inputs.
+ +The seeds are SHA-256("wraith:spending:" ‖ signature) and
SHA-256("wraith:viewing:" ‖ signature) — the same split the SDK performs.
st:xlm:.');
+ out.innerHTML = '';
+ setFieldError(metaInput, metaError, 'Recipient meta-address must start with st:xlm:.');
+ metaInput.focus();
return;
}
- if (!amount || Number.isNaN(Number(amount)) || Number(amount) <= 0) {
- out.innerHTML = statusBar('err', 'Amount must be a positive number.');
+ if (!amount || !Number.isFinite(Number(amount)) || Number(amount) <= 0) {
+ out.innerHTML = '';
+ setFieldError(amountInput, amountError, 'Amount must be a positive number.');
+ amountInput.focus();
+ return;
+ }
+
+ let spendingPubKey, viewingPubKey;
+ try {
+ ({ spendingPubKey, viewingPubKey } = decodeStealthMetaAddress(metaRaw));
+ } catch (err) {
+ out.innerHTML = '';
+ setFieldError(metaInput, metaError, `Recipient meta-address is invalid: ${err.message}`);
+ metaInput.focus();
return;
}
try {
- const { spendingPubKey, viewingPubKey } = decodeStealthMetaAddress(metaRaw);
// Deterministic one-time ephemeral keypair per click, so the demo is
// reproducible — the real protocol uses a random seed.
@@ -193,12 +273,13 @@ async function constructAnnouncement() {
${esc(JSON.stringify(event, null, 2))}
+ ${esc(JSON.stringify(event, null, 2))}
The stealth-sender contract transfers the asset and the
stealth-announcer contract emits this event in the same transaction.
${m.stealthAddress}`)}
${kvRow('Private scalar (signs withdrawals)', `${m.stealthPrivateScalar.toString()}`)}
- ${esc(JSON.stringify(tx, null, 2))}
+ ${esc(JSON.stringify(tx, null, 2))}
Privacy: space real withdrawals at least 1 hour apart and avoid uniform round amounts — see Privacy Best Practices.
`; @@ -379,6 +485,7 @@ function renderWithdrawal(btn, dest) { function resetStep(step) { if (!state.fixtures) return; const r = state.fixtures.recipient; + clearAllFieldErrors(); if (step === 'derive') { $('sigInput').value = r.signature; $('deriveResults').innerHTML = ''; @@ -441,11 +548,14 @@ async function boot() { try { await loadFixtures(); } catch (err) { - $('bootError').hidden = false; - $('bootError').innerHTML = statusBar('err', + // #bootError already has role="alert"; fill it before revealing it so the + // message is announced once, without a nested live region. + $('bootError').innerHTML = + ``; + $('bootError').hidden = false; return; } @@ -454,18 +564,26 @@ async function boot() { $('stepper-' + s).addEventListener('click', () => { _currentStep = s; activateStep(s); + focusStepHeading(s); + }); + $('reset-' + s).addEventListener('click', () => { + resetStep(s); + announce(`${STEP_LABELS[s]} step reset.`); }); - $('reset-' + s).addEventListener('click', () => resetStep(s)); - $('permalink-' + s).addEventListener('click', (e) => { - e.preventDefault(); - copyText(new URL($('permalink-' + s).dataset.url, location.href).href, $('permalink-' + s)); + $('permalink-' + s).addEventListener('click', () => { + copyText(new URL($('permalink-' + s).dataset.url, location.href).href, + $('permalink-' + s), 'Permalink copied to clipboard.'); }); } $('deriveBtn').addEventListener('click', runDerive); $('constructBtn').addEventListener('click', constructAnnouncement); $('scanBtn').addEventListener('click', runScan); - $('loadFixture').addEventListener('click', () => resetStep('scan')); + $('loadFixture').addEventListener('click', () => { + resetStep('scan'); + announce('Demo keys and fixture data loaded.'); + $('scanMeta').focus(); + }); // Read the step (and optional prefilled inputs) from the URL. const params = new URLSearchParams(location.search); diff --git a/scripts/playground/tests/a11y.spec.ts b/scripts/playground/tests/a11y.spec.ts new file mode 100644 index 0000000..ed838d6 --- /dev/null +++ b/scripts/playground/tests/a11y.spec.ts @@ -0,0 +1,283 @@ +import AxeBuilder from "@axe-core/playwright"; +import { expect, test, type Page } from "@playwright/test"; + +// Accessibility and keyboard coverage for the Wraith Stealth Playground. +// +// The playground is embedded in docs pages, so it has to work for keyboard and +// assistive-technology users at desktop, 200% zoom, and mobile widths without a +// pointer. These tests complement playground.spec.ts (which covers the smoke +// flow and the zero-external-request gate) and enforce the issue #220 +// acceptance criteria. +// +// Rule exceptions: none. The palette and markup are fixed rather than excluding +// axe rules, so any serious/critical violation is a failure. + +const WCAG_TAGS = ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22a", "wcag22aa"]; + +async function analyze(page: Page, context: string) { + const results = await new AxeBuilder({ page }).withTags(WCAG_TAGS).analyze(); + const blocking = results.violations.filter( + (v) => v.impact === "serious" || v.impact === "critical", + ); + const summary = blocking + .map((v) => + `${v.id} (${v.impact}) ${v.help}\n` + + v.nodes.map((n) => ` ${n.target.join(" ")}: ${n.failureSummary}`).join("\n"), + ) + .join("\n\n"); + expect(blocking, `${context}\n${summary}`).toEqual([]); +} + +// Press Tab until the given element owns focus. This is deliberately keyboard +// only: no locator.click(), no programmatic focus(), no pointer events. +async function tabTo(page: Page, selector: string, maxTabs = 80) { + const target = page.locator(selector).first(); + for (let i = 0; i < maxTabs; i++) { + await page.keyboard.press("Tab"); + if (await target.evaluate((el) => el === document.activeElement)) return; + } + throw new Error(`Tab did not reach ${selector} within ${maxTabs} presses`); +} + +async function assertNoHorizontalOverflow(page: Page, context: string) { + const metrics = await page.evaluate(() => ({ + scrollWidth: document.documentElement.scrollWidth, + clientWidth: document.documentElement.clientWidth, + })); + expect( + metrics.scrollWidth, + `${context} must reflow without horizontal scrolling (${metrics.scrollWidth}px > ${metrics.clientWidth}px)`, + ).toBeLessThanOrEqual(metrics.clientWidth + 1); +} + +// The whole guided flow, activated only with Tab and Enter/Space aside from +// typing the amount. +async function completeFlowWithKeyboard(page: Page) { + await page.goto("/index.html"); + + await tabTo(page, "#deriveBtn"); + await page.keyboard.press("Enter"); + await expect(page.locator("#deriveResults .card-accent")).toContainText("st:xlm:"); + + await tabTo(page, "#stepper-send"); + await page.keyboard.press("Enter"); + // Activating a step moves focus to its heading. + await expect(page.locator("#panel-send-title")).toBeFocused(); + await tabTo(page, "#sendAmount"); + await page.keyboard.type("10"); + await tabTo(page, "#constructBtn"); + await page.keyboard.press("Enter"); + await expect(page.locator("#sendResults")).toContainText("added to the scan batch"); + + await tabTo(page, "#stepper-scan"); + await page.keyboard.press("Enter"); + await tabTo(page, "#loadFixture"); + await page.keyboard.press("Enter"); + await tabTo(page, "#scanBtn"); + await page.keyboard.press("Enter"); + await expect(page.locator("#scanResults [role='status']")).toContainText("matches found"); + + await tabTo(page, "#stepper-withdraw"); + await page.keyboard.press("Enter"); + await expect(page.locator("#withdrawResults")).toContainText("withdrawable stealth balance"); + await tabTo(page, ".withdraw-btn"); + await page.keyboard.press("Enter"); + await expect(page.locator("#withdrawResults .code-block").first()).toContainText( + "stealth private scalar", + ); +} + +test("no serious or critical axe violations across the guided flow", async ({ page }) => { + await page.goto("/index.html?step=derive"); + await analyze(page, "derive step"); + + await page.locator("#deriveBtn").click(); + await expect(page.locator("#deriveResults .card-accent")).toBeVisible(); + await analyze(page, "derive results"); + + await page.locator("#stepper-send").click(); + await page.locator("#sendAmount").fill("10"); + await page.locator("#constructBtn").click(); + await expect(page.locator("#sendResults .card-accent")).toBeVisible(); + // Expand the event JSON so the scrollable code region is exposed. + await page.locator("#sendResults details summary").click(); + await analyze(page, "send results"); + + await page.locator("#stepper-scan").click(); + await page.locator("#loadFixture").click(); + await page.locator("#scanBtn").click(); + await expect(page.locator("#scanResults .match-card")).toHaveCount(3); + // Expand the announcement table so its caption and headers are scanned. + await page.locator("#panel-scan details.fixture-section summary").click(); + await analyze(page, "scan results"); + + await page.locator("#stepper-withdraw").click(); + await expect(page.locator("#withdrawResults .withdraw-btn")).toHaveCount(3); + await page.locator("#withdrawResults .withdraw-btn").first().click(); + await analyze(page, "withdraw results"); +}); + +test("no serious or critical axe violations at mobile width", async ({ page }) => { + await page.setViewportSize({ width: 360, height: 740 }); + await page.goto("/index.html?step=derive"); + await page.locator("#deriveBtn").click(); + await expect(page.locator("#deriveResults .card-accent")).toBeVisible(); + await analyze(page, "derive results at 360px"); + + await page.locator("#stepper-scan").click(); + await page.locator("#loadFixture").click(); + await page.locator("#scanBtn").click(); + // The fixture batch alone matches twice; the Send step adds the third. + await expect(page.locator("#scanResults .match-card")).toHaveCount(2); + await analyze(page, "scan results at 360px"); +}); + +test("every cryptographic input and select has an accessible name", async ({ page }) => { + await page.goto("/index.html?step=derive"); + await expect(page.getByLabel(/Wallet signature/)).toBeVisible(); + + await page.locator("#stepper-send").click(); + await expect(page.getByLabel(/Recipient meta-address/)).toBeVisible(); + await expect(page.getByLabel("Asset")).toHaveValue("XLM"); + await expect(page.getByLabel("Amount")).toBeVisible(); + + await page.locator("#stepper-scan").click(); + await expect(page.getByLabel(/Stealth meta-address/)).toBeVisible(); + await expect(page.getByLabel(/Viewing key/)).toBeVisible(); + await expect(page.getByLabel(/Spending scalar/)).toBeVisible(); + + await page.locator("#stepper-withdraw").click(); + await expect(page.getByLabel(/Destination wallet/)).toBeVisible(); + + // Errors are associated with the input they describe, not just global text. + await page.locator("#stepper-derive").click(); + await expect(page.locator("#sigInput")).toHaveAttribute("aria-describedby", "sigError"); + await expect(page.locator("#sendMeta")).toHaveAttribute("aria-describedby", "sendMetaError"); + await expect(page.locator("#scanVk")).toHaveAttribute("aria-describedby", "scanVkError"); +}); + +test("tab order follows the visual order of the stepper and derive panel", async ({ page }) => { + await page.goto("/index.html?step=derive"); + await page.locator("#stepper-derive").focus(); + + for (const id of [ + "stepper-send", + "stepper-scan", + "stepper-withdraw", + "sigInput", + "deriveBtn", + "reset-derive", + "permalink-derive", + ]) { + await page.keyboard.press("Tab"); + await expect(page.locator(`#${id}`)).toBeFocused(); + } +}); + +test("stepper exposes the current step and moves focus to its heading", async ({ page }) => { + await page.goto("/index.html?step=derive"); + await expect(page.locator("#stepper-derive")).toHaveAttribute("aria-current", "step"); + await expect(page.locator("#stepper-send")).not.toHaveAttribute("aria-current", "step"); + + await page.locator("#stepper-scan").click(); + await expect(page.locator("#stepper-scan")).toHaveAttribute("aria-current", "step"); + await expect(page.locator("#stepper-derive")).not.toHaveAttribute("aria-current", "step"); + await expect(page.locator("#panel-scan-title")).toBeFocused(); +}); + +test("invalid signature moves focus, announces the error, and keeps the input", async ({ + page, +}) => { + await page.goto("/index.html?step=derive"); + await page.locator("#sigInput").fill("abc123"); + await page.locator("#deriveBtn").click(); + + await expect(page.locator("#sigInput")).toBeFocused(); + await expect(page.locator("#sigInput")).toHaveAttribute("aria-invalid", "true"); + await expect(page.locator("#sigInput")).toHaveValue("abc123"); + await expect(page.locator("#sigError")).toBeVisible(); + await expect(page.getByRole("alert")).toContainText("128 hex characters"); + await expect(page.locator("#deriveResults")).toHaveText(""); +}); + +test("scan errors focus the first invalid field and preserve all input", async ({ page }) => { + await page.goto("/index.html?step=scan"); + await expect(page.locator("#scanVk")).toHaveValue(/^[0-9a-f]{64}$/); + + await page.locator("#scanMeta").fill("not-a-meta-address"); + await page.locator("#scanVk").fill("zz"); + await page.locator("#scanScalar").fill("not-a-number"); + await page.locator("#scanBtn").click(); + + await expect(page.locator("#scanMeta")).toBeFocused(); + await expect(page.locator("#scanMeta")).toHaveAttribute("aria-invalid", "true"); + await expect(page.locator("#scanVk")).toHaveAttribute("aria-invalid", "true"); + await expect(page.locator("#scanScalar")).toHaveAttribute("aria-invalid", "true"); + await expect(page.locator("#scanVk")).toHaveValue("zz"); + await expect(page.locator("#scanScalar")).toHaveValue("not-a-number"); + await expect(page.locator("#scanMetaError")).toContainText( + "Meta-address must start with st:xlm:", + ); + await expect(page.locator("#scanResults")).toHaveText(""); +}); + +test("result statuses and copy actions announce through live regions", async ({ page }) => { + await page.goto("/index.html?step=derive"); + await page.locator("#deriveBtn").click(); + await expect(page.locator("#deriveResults [role='status']")).toContainText("Keys derived"); + + await page.locator("#copyMetaBtn").click(); + await expect(page.locator("#copyMetaBtn")).toContainText("Copied ✓"); + await expect(page.locator("#liveRegion")).toHaveText( + "Stealth meta-address copied to clipboard.", + ); + + await page.locator("#permalink-derive").click(); + await expect(page.locator("#liveRegion")).toHaveText("Permalink copied to clipboard."); + await expect(page.locator("#permalink-derive")).toContainText("Copied ✓"); + + await page.locator("#stepper-scan").click(); + await page.locator("#loadFixture").click(); + await page.locator("#scanBtn").click(); + const scanStatus = page.locator("#scanResults [role='status']"); + await expect(scanStatus).toContainText("matches found"); + await expect(scanStatus).toHaveAttribute("aria-atomic", "true"); +}); + +test("reduced motion disables the scanning pulse", async ({ page }) => { + await page.goto("/index.html?step=derive"); + + const normal = await page.evaluate(() => { + const dot = document.createElement("span"); + dot.className = "dot dot-scanning"; + document.body.appendChild(dot); + const name = getComputedStyle(dot).animationName; + dot.remove(); + return name; + }); + expect(normal).toBe("pulse"); + + await page.emulateMedia({ reducedMotion: "reduce" }); + const reduced = await page.evaluate(() => { + const dot = document.createElement("span"); + dot.className = "dot dot-scanning"; + document.body.appendChild(dot); + const style = getComputedStyle(dot); + const result = { name: style.animationName, duration: style.animationDuration }; + dot.remove(); + return result; + }); + expect(reduced.name).toBe("none"); + expect(parseFloat(reduced.duration)).toBeLessThanOrEqual(0.01); +}); + +test("critical flow works with the keyboard at 200% zoom and mobile width", async ({ page }) => { + for (const viewport of [ + { width: 640, height: 512, label: "200% zoom (640x512 CSS px)" }, + { width: 360, height: 740, label: "mobile width (360x740 CSS px)" }, + ]) { + await page.setViewportSize(viewport); + await completeFlowWithKeyboard(page); + await assertNoHorizontalOverflow(page, viewport.label); + } +}); diff --git a/scripts/playground/tests/playwright.config.ts b/scripts/playground/tests/playwright.config.ts index ee7340a..2627f0c 100644 --- a/scripts/playground/tests/playwright.config.ts +++ b/scripts/playground/tests/playwright.config.ts @@ -2,7 +2,7 @@ import path from "node:path"; import { fileURLToPath } from "node:url"; import { defineConfig } from "@playwright/test"; -// Playwright config for the Wraith Stealth Playground smoke tests. +// Playwright config for the Wraith Stealth Playground smoke and accessibility tests. // The playground is served over HTTP (not file://) because module script // loading and CSP behave differently on file://. const __dirname = path.dirname(fileURLToPath(import.meta.url));