aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-09-12 10:05:10 -0700
committerAdam Soltys <[email protected]>2026-09-12 10:05:10 -0700
commita846211262f37238c001e5210938749294f8db6a (patch)
treeeb2f1c313051a739ef18a32d39bc4988a63e44fd /tools
parentcab447766734cb99821c36988ebc8d27a0bce228 (diff)
downloadcoinosv3-a846211262f37238c001e5210938749294f8db6a.tar.gz
coinosv3-a846211262f37238c001e5210938749294f8db6a.zip
UnifiedPush: reach a phone that has no Google in it.
Web push on Android is Firebase's, so a phone without Google Play Services — GrapheneOS, CalyxOS, any de-Googled Android — cannot be woken by a web app at all. UnifiedPush is the way that doesn't involve Google: the user runs a distributor (ntfy and friends), apps ask it for an endpoint, and whoever wants to reach the device POSTs to that endpoint. THE WRAPPER speaks the protocol directly — four broadcasts each way, so it pulls in no library; an APK this small has no business growing a Kotlin runtime for eight intents. It asks the distributor on every launch (the call is idempotent, and it's how a distributor installed later gets noticed), raises a notification when a message arrives, and acknowledges it so the distributor stops resending. THE ENDPOINT reaches the web app on the launch URL as ?up=, the same road payment intents already travel — because the distributor talks to the app and only the web app knows which pubkeys are worth watching. It's registered with the notifier in place of a browser subscription, for notifications and for NWC alike, and needs neither permission nor push service. THE NOTIFIER sends to either kind: one deliver() that POSTs the payload to a UnifiedPush endpoint, or hands it to web-push as before. Same payloads, same 404/410 pruning. The endpoint is the only secret there, so it's never logged in full. Verified: a POST to a live ntfy endpoint delivers the payload byte for byte, so the app parses exactly what the notifier sent; the APK builds, carries the receiver, and is signed with the certificate assetlinks already pins (v1.6). tools/unifiedpush-test.js drives a browser with no push service and checks the endpoint is taken off the URL, kept, and registered. Honest about the limit: a UnifiedPush message wakes the ANDROID app, not Chrome's service worker, and the wallet's keys live in the browser's storage where nothing here can reach them. So a zap request arrives as a notification you tap, and the wallet answers when it opens — one tap instead of none. Automatic answering while closed still needs a browser with a push service. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_019mrt228Upn9nNCwGixzSLx
Diffstat (limited to 'tools')
-rw-r--r--tools/unifiedpush-test.js83
1 files changed, 83 insertions, 0 deletions
diff --git a/tools/unifiedpush-test.js b/tools/unifiedpush-test.js
new file mode 100644
index 0000000..71fbcde
--- /dev/null
+++ b/tools/unifiedpush-test.js
@@ -0,0 +1,83 @@
+// UnifiedPush: the way a phone without Google Play Services can be reached.
+//
+// The Android wrapper asks a distributor (ntfy and friends) for an endpoint
+// and hands it to the web app on the launch URL as ?up=. The web app is what
+// knows which pubkeys to watch, so it does the registering; the notifier then
+// POSTs payloads straight to that endpoint instead of through Firebase.
+//
+// This checks the web half: the endpoint is picked up, kept, registered with
+// the notifier, and used in place of a browser subscription that could never
+// have worked on such a phone.
+//
+// Run: bun tools/unifiedpush-test.js
+import puppeteer from 'puppeteer-core';
+import { generateMnemonic } from '@scure/bip39';
+import { wordlist } from '@scure/bip39/wordlists/english';
+import { buildHtml } from '../build.js';
+const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
+let ok = true;
+const check = (n, c, d = '') => { console.log(` ${c ? '✓' : '✗'} ${n}${d ? ' — ' + d : ''}`); if (!c) ok = false; };
+const html = await buildHtml({ minify: true, pwa: false });
+const server = Bun.serve({ port: 5263, fetch: () => new Response(html, { headers: { 'content-type': 'text/html' } }) });
+const browser = await puppeteer.launch({ executablePath: '/usr/bin/google-chrome', headless: 'new', args: ['--no-sandbox'] });
+const page = await browser.newPage();
+// a phone with no push service at all, which is the whole point of the exercise
+await page.evaluateOnNewDocument(() => {
+ const reg = {
+ pushManager: {
+ getSubscription: () => Promise.resolve(null),
+ subscribe: () => Promise.reject(new DOMException('Registration failed - push service error', 'AbortError')),
+ },
+ showNotification: () => Promise.resolve(),
+ };
+ Object.defineProperty(navigator.serviceWorker, 'ready', { get: () => Promise.resolve(reg) });
+ Notification.requestPermission = () => Promise.resolve('granted');
+ Object.defineProperty(Notification, 'permission', { get: () => 'granted' });
+});
+// watch what it tries to tell the notifier
+const registrations = [];
+await page.setRequestInterception(true);
+page.on('request', (r) => {
+ if (r.url().includes('nwcpush.coinos.io/register') && r.method() === 'POST') {
+ try { registrations.push(JSON.parse(r.postData() || '{}')); } catch {}
+ return r.respond({ status: 200, contentType: 'application/json', body: '{"ok":true}' });
+ }
+ if (r.url().includes('nwcpush.coinos.io/vapid')) return r.respond({ status: 200, contentType: 'application/json', body: '{"publicKey":"BKd0FOtD3Y9gAB3ZFDkCPlBtm0IhEbiKUeYUCE7Tuh9nWDOAhBKiZ0dPYjYQkHhVYyPNPUn0E-gLRPPqzYyAWmA"}' });
+ return r.continue();
+});
+const click = (t) => page.evaluate((x) => { const e = [...document.querySelectorAll('button')].find((n) => n.textContent.trim().toLowerCase().includes(x)); if (e) { e.click(); return true; } return false; }, t);
+const waitText = async (x, ms = 25000) => { for (let i = 0; i < ms/250; i++) { if ((await page.evaluate(() => document.body.innerText)).toLowerCase().includes(x)) return true; await sleep(250); } return false; };
+const ENDPOINT = 'https://ntfy.sh/upTESTendpoint123';
+try {
+ await page.setViewport({ width: 390, height: 844 });
+ await page.goto('http://localhost:5263/', { waitUntil: 'domcontentloaded' });
+ await page.evaluate(() => localStorage.setItem('btc-wallet-network', 'regtest'));
+ await page.reload({ waitUntil: 'domcontentloaded' });
+ await sleep(400);
+ await click('get started'); await sleep(500);
+ await click('import existing'); await sleep(400);
+ await page.waitForSelector('textarea');
+ await page.type('textarea', generateMnemonic(wordlist));
+ await click('open wallet');
+ await waitText('receive', 20000);
+
+ // the wrapper launches the web app with the endpoint on the URL
+ await page.goto('http://localhost:5263/?up=' + encodeURIComponent(ENDPOINT), { waitUntil: 'domcontentloaded' });
+ await waitText('receive', 20000);
+ await sleep(2500);
+
+ const kept = await page.evaluate(() => localStorage.getItem('coinos-unifiedpush'));
+ check('the endpoint is taken off the launch URL and kept', kept === ENDPOINT, kept || 'nothing stored');
+ check('...and the URL is tidied afterwards', !(await page.url()).includes('up='), await page.url());
+
+ const up = registrations.find((r) => r.subscription && r.subscription.unifiedpush);
+ check('the notifier is told to use it', !!up, JSON.stringify(registrations.map((r) => Object.keys(r))) || 'no registration');
+ check('...with the endpoint, marked as UnifiedPush', up && up.subscription.endpoint === ENDPOINT, up ? up.subscription.endpoint : '');
+ check('...and the watch list rides along', !!(up && up.notify), up ? Object.keys(up.notify || {}).join(',') : '');
+
+ const txt = await page.evaluate(() => document.body.innerText);
+ check('the browser\'s own dead push is no longer the story', !/no push service/i.test(txt),
+ (txt.match(/[^\n]*push service[^\n]*/i) || [''])[0].slice(0, 50));
+} finally { await browser.close(); server.stop(true); }
+console.log(ok ? '\n✅ a de-Googled phone can be reached' : '\n❌ failed');
+process.exit(ok ? 0 : 1);