Bento, the office suite that fits in a file
TypeScript mit-licenseofficeoffice-365office-suiteoffice-toolsoffice365open-sourcepowerpointself-hostedsingle-page-appslidesslideshareslideshowslideshow-galleryslideshow-makerslideshows
bento.page: prepared passkey association files (Apple webcredentials, Android get_login_creds) (#758)
nyblnetc5ccb74d1f50
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 9035bb7c..05c23723 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -2685,3 +2685,10 @@ jobs:# that refuses the recovery copy gets the notice once, held to read;# pt and de show slides' words. Planted in bento-spaces-autosave.run: node scripts/test-spaces-recovery-browser.mjs+ - name: bento.page passkey association files never publish a placeholder+ # scripts/well-known.mjs fills /.well-known/apple-app-site-association+ # and assetlinks.json from site-src/well-known/ once the Apple team id+ # and the Play signing fingerprint exist. It writes only what it was+ # given, refuses a malformed value, and never emits a placeholder: the+ # platforms cache these files, so a wrong one is worse than none.+ run: node scripts/test-well-known.tsdiff --git a/scripts/test-well-known.ts b/scripts/test-well-known.tsnew file mode 100644index 00000000..6eec8b0b--- /dev/null+++ b/scripts/test-well-known.ts@@ -0,0 +1,81 @@+#!/usr/bin/env node+// SPDX-License-Identifier: MIT+// Copyright (c) 2026 The Bento authors+// bento.page's passkey association files: scripts/well-known.mjs never+// publishes a placeholder, writes only what it was given, and refuses values+// of the wrong shape.+//+// node scripts/test-well-known.ts+import { execFileSync } from 'node:child_process'+import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs'+import { tmpdir } from 'node:os'+import { join } from 'node:path'++let fails = 0, passes = 0+const ok = (c: unknown, n: string) => { if (c) passes++; else { fails++; console.log('FAIL ' + n) } }+const run = (args: string[]) => {+ try { return { code: 0, out: execFileSync('node', ['scripts/well-known.mjs', ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }) } } catch (e) {+ const err = e as { status?: number; stderr?: string }+ return { code: err.status ?? 1, out: String(err.stderr ?? '') }+ }+}+const TEAM = 'AB12CD34EF'+const FP = Array.from({ length: 32 }, (_, i) => i.toString(16).padStart(2, '0').toUpperCase()).join(':')+const tmp = () => mkdtempSync(join(tmpdir(), 'wk-'))+const read = (d: string, f: string) => readFileSync(join(d, '.well-known', f), 'utf8')++// templates: valid JSON, each carries its placeholder, the real app id+for (const f of ['assetlinks.json', 'apple-app-site-association']) {+ const t = readFileSync(join('site-src/well-known', f), 'utf8')+ let parsed = false+ try { JSON.parse(t); parsed = true } catch { /* */ }+ ok(parsed, `${f}: template is valid JSON`)+ ok(/__[A-Z0-9_]+__/.test(t), `${f}: template is marked with a placeholder`)+ ok(t.includes('page.bento.home'), `${f}: names the bento/home app (page.bento.home)`)+}++// no values: checks the templates, writes nothing+{+ const d = tmp()+ const r = run(['--out', d])+ ok(r.code === 0 && !existsSync(join(d, '.well-known')), 'no values → nothing written')+ rmSync(d, { recursive: true, force: true })+}++// both values: exact, placeholder-free, valid JSON with the right shapes+{+ const d = tmp()+ const r = run(['--out', d, '--apple-team', TEAM, '--play-sha256', FP.toLowerCase()])+ ok(r.code === 0, `both values → success (${r.out.trim()})`)+ const aasa = JSON.parse(read(d, 'apple-app-site-association'))+ ok(JSON.stringify(aasa.webcredentials.apps) === JSON.stringify([`${TEAM}.page.bento.home`]), 'AASA: webcredentials app is TEAMID.page.bento.home')+ const al = JSON.parse(read(d, 'assetlinks.json'))+ ok(al[0].relation.includes('delegate_permission/common.get_login_creds'), 'assetlinks: get_login_creds (passkeys)')+ ok(al[0].target.package_name === 'page.bento.home', 'assetlinks: package page.bento.home')+ ok(al[0].target.sha256_cert_fingerprints[0] === FP, 'assetlinks: fingerprint normalised to uppercase')+ for (const f of ['assetlinks.json', 'apple-app-site-association']) ok(!/__[A-Z0-9_]+__/.test(read(d, f)), `${f}: no placeholder in the output`)+ rmSync(d, { recursive: true, force: true })+}++// one value: writes ONLY that file (M1 and M2 may arrive at different times)+{+ const d = tmp()+ ok(run(['--out', d, '--apple-team', TEAM]).code === 0, 'Apple id only → success')+ ok(existsSync(join(d, '.well-known/apple-app-site-association')) && !existsSync(join(d, '.well-known/assetlinks.json')), 'Apple id only → assetlinks.json NOT written')+ rmSync(d, { recursive: true, force: true })+}++// wrong shapes are refused, and refusal writes nothing+for (const [flag, bad, name] of [+ ['--apple-team', 'abc', 'short team id'], ['--apple-team', '__APPLE_TEAM_ID__', 'the placeholder itself'],+ ['--play-sha256', 'AA:BB', 'short fingerprint'], ['--play-sha256', FP.replace(/:/g, ''), 'fingerprint without colons'],+ ['--play-sha256', '__PLAY_APP_SIGNING_SHA256__', 'the placeholder itself'],+]) {+ const d = tmp()+ const r = run(['--out', d, flag, bad])+ ok(r.code !== 0 && !existsSync(join(d, '.well-known')), `refused: ${name}`)+ rmSync(d, { recursive: true, force: true })+}++console.log(`${passes} passed, ${fails} failed`)+process.exit(fails)diff --git a/scripts/well-known.mjs b/scripts/well-known.mjsnew file mode 100644index 00000000..96f31f4d--- /dev/null+++ b/scripts/well-known.mjs@@ -0,0 +1,85 @@+#!/usr/bin/env node+// SPDX-License-Identifier: MIT+// Copyright (c) 2026 The Bento authors+//+// Fill bento.page's two association files and write them into the site.+//+// node scripts/well-known.mjs [--apple-team TEAMID] [--play-sha256 AA:BB:…] [--out site]+//+// They let passkeys created for the relying party bento.page be used by the+// bento/home apps: Apple reads /.well-known/apple-app-site-association+// (`webcredentials`), Android reads /.well-known/assetlinks.json+// (`get_login_creds`). The templates in site-src/well-known/ carry+// PLACEHOLDERS — the Apple developer team id and the Play app-signing+// certificate fingerprint exist only once those accounts do.+//+// A placeholder must never be published: a wrong association file is worse+// than none, because the platform caches it. So this script writes ONLY the+// files whose value was given, validates the value's shape, and refuses any+// output that still contains a placeholder. Run with neither flag to check the+// templates and write nothing.+//+// Publishing is the maintainer's: this writes into the local `site/` staging+// directory, and scripts/publish-site.mjs is what goes live.+//+// Serving notes for whoever publishes:+// · both files must be served over HTTPS at exactly these paths, with no+// redirect; site/ already carries .nojekyll, so GitHub Pages serves the+// dot-directory.+// · apple-app-site-association has no extension, so GitHub Pages serves it+// as application/octet-stream. Apple's CDN fetches it for the devices;+// confirm it has picked the file up at+// https://app-site-association.cdn-apple.com/a/v1/bento.page before+// relying on it.++import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'+import { dirname, join } from 'node:path'+import { fileURLToPath } from 'node:url'++const root = join(dirname(fileURLToPath(import.meta.url)), '..')+const TEMPLATES = join(root, 'site-src/well-known')++export const FILES = {+ apple: { name: 'apple-app-site-association', placeholder: '__APPLE_TEAM_ID__', valid: /^[A-Z0-9]{10}$/ },+ play: { name: 'assetlinks.json', placeholder: '__PLAY_APP_SIGNING_SHA256__', valid: /^([0-9A-F]{2}:){31}[0-9A-F]{2}$/ },+}+const ANY_PLACEHOLDER = /__[A-Z0-9_]+__/++/** Fill one template. Returns the text, or throws with a reason. */+export function fill(kind, value) {+ const f = FILES[kind]+ const tpl = readFileSync(join(TEMPLATES, f.name), 'utf8')+ JSON.parse(tpl) // the template itself must be valid JSON+ if (!tpl.includes(f.placeholder)) throw new Error(`${f.name}: template has no ${f.placeholder}`)+ if (!f.valid.test(value)) throw new Error(`${f.name}: "${value}" is not a valid ${kind === 'apple' ? 'Apple team id (10 characters, A–Z 0–9)' : 'SHA-256 fingerprint (32 uppercase hex bytes, colon-separated)'}`)+ const out = tpl.split(f.placeholder).join(value)+ if (ANY_PLACEHOLDER.test(out)) throw new Error(`${f.name}: a placeholder is still present after filling — refusing`)+ JSON.parse(out)+ return out+}++function main(argv) {+ const arg = (k) => { const i = argv.indexOf(k); return i >= 0 ? argv[i + 1] : undefined }+ const out = arg('--out') ?? join(root, 'site')+ const given = { apple: arg('--apple-team'), play: arg('--play-sha256')?.toUpperCase() }+ // always check every template, so a broken one is caught even when unused+ for (const f of Object.values(FILES)) {+ const tpl = readFileSync(join(TEMPLATES, f.name), 'utf8')+ JSON.parse(tpl)+ if (!tpl.includes(f.placeholder)) throw new Error(`${f.name}: template has no ${f.placeholder}`)+ }+ const wrote = []+ for (const kind of Object.keys(FILES)) {+ if (given[kind] === undefined) continue+ const text = fill(kind, given[kind])+ const dir = join(out, '.well-known')+ if (!existsSync(dir)) mkdirSync(dir, { recursive: true })+ writeFileSync(join(dir, FILES[kind].name), text)+ wrote.push(FILES[kind].name)+ }+ console.log(wrote.length ? `wrote ${wrote.join(', ')} into ${join(out, '.well-known')}` : 'templates OK; nothing written (no values given)')+}++if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) {+ try { main(process.argv.slice(2)) } catch (e) { console.error(String(e.message || e)); process.exit(1) }+}diff --git a/site-src/well-known/apple-app-site-association b/site-src/well-known/apple-app-site-associationnew file mode 100644index 00000000..53a9962d--- /dev/null+++ b/site-src/well-known/apple-app-site-association@@ -0,0 +1,5 @@+{+ "webcredentials": {+ "apps": ["__APPLE_TEAM_ID__.page.bento.home"]+ }+}diff --git a/site-src/well-known/assetlinks.json b/site-src/well-known/assetlinks.jsonnew file mode 100644index 00000000..44c63eaf--- /dev/null+++ b/site-src/well-known/assetlinks.json@@ -0,0 +1,10 @@+[+ {+ "relation": ["delegate_permission/common.get_login_creds"],+ "target": {+ "namespace": "android_app",+ "package_name": "page.bento.home",+ "sha256_cert_fingerprints": ["__PLAY_APP_SIGNING_SHA256__"]+ }+ }+]