aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-11-07 19:28:24 -0700
committerAdam Soltys <[email protected]>2026-11-07 19:28:24 -0700
commit3988354e068de04563aac6b250a0e7612f16c2ec (patch)
tree55203c16feb086e8b4f6f74c7b9266cd9f0d50d4 /tools
parent48eb895cfb21c7e679344eaafebd446c4ccd949b (diff)
downloadcoinosv3-3988354e068de04563aac6b250a0e7612f16c2ec.tar.gz
coinosv3-3988354e068de04563aac6b250a0e7612f16c2ec.zip
A zap on your Zapstore app reads "zapped your app PAFF" in Notifications and opens the app's Zapstore page. "Clicking this franzap zap notification keeps bringing me to his profile not a note" (Adam, 2026-11-07): franzap's 10k "Love it" was a zap on the PAFF listing (kind 32267, a-tagged in the zap request), but Zapstore's receipt carries only p and P, so the row read as a zap on nothing and fell through to the zapper's profile. Rows now take a zap's address from the receipt or, failing that, the zap request inside it (zapAddrOf; streams get that too); a 32267 one is an app zap, named from relay.zapstore.dev once per session, opening zapstore.dev/apps/<id>. A row saved before reads its receipt by id on the first tap and goes where it says; a relay handing the receipt again heals it as well. tools/notif-app-zap-test.js
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VMan6Ts5Tktega8VbLg31q
Diffstat (limited to 'tools')
-rw-r--r--tools/notif-app-zap-test.js109
1 files changed, 109 insertions, 0 deletions
diff --git a/tools/notif-app-zap-test.js b/tools/notif-app-zap-test.js
new file mode 100644
index 0000000..3ee2030
--- /dev/null
+++ b/tools/notif-app-zap-test.js
@@ -0,0 +1,109 @@
+// Notifications: a zap on your Zapstore app listing (kind 32267) reads
+// "zapped your app PAFF" and opens the app's Zapstore page. It opened the
+// zapper's profile: Zapstore's receipt carries no a tag (only the zap request
+// inside it does), so the row looked like a zap on nothing (Adam, 2026-11-07:
+// "clicking this franzap zap notification keeps bringing me to his profile").
+// A row saved before reads the receipt once on tap and goes there too.
+// Run: bun tools/notif-app-zap-test.js
+import puppeteer, { seedWords, skipSeedCheck } from './puppeteer.js';
+import { cacheKeyFor } from '../src/wallet.js';
+import { generateSecretKey, getPublicKey, finalizeEvent } from 'nostr-tools/pure';
+import { privateKeyFromSeedWords } from 'nostr-tools/nip06';
+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 A = generateSecretKey(), B = generateSecretKey();
+const now = Math.floor(Date.now() / 1000);
+const PNG = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==', 'base64');
+const html = await buildHtml({ minify: true, pwa: false });
+const server = Bun.serve({ port: 5317, fetch: (req) => {
+ const path = new URL(req.url).pathname;
+ if (path.endsWith('.png')) return new Response(PNG, { headers: { 'content-type': 'image/png' } });
+ if (path.startsWith('/punks') || path === '/verify-worker.js') return new Response(Bun.file('dist' + path));
+ return 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();
+const errs = [];
+page.on('pageerror', (e) => errs.push(String(e)));
+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; };
+
+try {
+ await page.setViewport({ width: 390, height: 844 });
+ await page.goto('http://localhost:5317/', { waitUntil: 'domcontentloaded' });
+ await page.evaluate(() => localStorage.setItem('btc-wallet-network', 'regtest'));
+ await page.reload({ waitUntil: 'domcontentloaded' }); await sleep(400);
+ await click('create a new wallet'); await sleep(600);
+ await seedWords(page);
+ const mn = (await page.$$eval('.words .w .t', (l) => l.map((e) => e.textContent.trim()))).join(' ');
+ await skipSeedCheck(page);
+ await waitText('receive', 20000);
+ const base = cacheKeyFor(mn + '\n');
+ const ME = getPublicKey(privateKeyFromSeedWords(mn));
+ const APP = '32267:' + 'c'.repeat(64) + ':club.paff.app';
+ const zap = (sk, sats, ts, content) => {
+ const req = finalizeEvent({ kind: 9734, created_at: ts, content, tags: [['p', ME], ['amount', String(sats * 1000)], ['a', APP]] }, sk);
+ // the receipt Zapstore's LNURL server publishes: p and P, no a tag
+ return finalizeEvent({ kind: 9735, created_at: ts, content: '', tags: [['p', ME], ['P', req.pubkey], ['amount', String(sats * 1000)], ['description', JSON.stringify(req)]] }, generateSecretKey());
+ };
+ const OLD = zap(A, 10000, now - 120, 'Love it'); // saved by the old code, without the app
+ const NEW = zap(B, 2100, now - 60, 'great app');
+ const LISTING = finalizeEvent({ kind: 32267, created_at: now - 3600, content: '', tags: [['d', 'club.paff.app'], ['name', 'PAFF']] }, generateSecretKey());
+ await page.evaluateOnNewDocument((evs, listing) => {
+ window.__opened = [];
+ window.open = (u) => { window.__opened.push(u); return null; };
+ const Real = window.WebSocket;
+ window.WebSocket = function (...a) {
+ const ws = new Real(...a);
+ const send = ws.send.bind(ws);
+ ws.send = (data) => {
+ try {
+ const m = JSON.parse(data);
+ if (m[0] === 'REQ') {
+ const fs = m.slice(2);
+ const hit = [
+ // the notifications sync only hands the NEW one; the old row is already held
+ ...evs.slice(1).filter(() => fs.some((f) => (f.kinds || []).includes(9735) && (f['#p'] || []).length)),
+ ...evs.filter((ev) => fs.some((f) => (f.ids || []).includes(ev.id))),
+ ...(fs.some((f) => (f.kinds || []).includes(32267)) ? [listing] : []),
+ ];
+ setTimeout(() => {
+ for (const e of hit) ws.dispatchEvent(new MessageEvent('message', { data: JSON.stringify(['EVENT', m[1], e]) }));
+ ws.dispatchEvent(new MessageEvent('message', { data: JSON.stringify(['EOSE', m[1]]) }));
+ }, 0);
+ return;
+ }
+ if (m[0] === 'EVENT' || m[0] === 'NEG-OPEN') return;
+ } catch {}
+ return send(data);
+ };
+ return ws;
+ };
+ window.WebSocket.prototype = Real.prototype; Object.assign(window.WebSocket, Real);
+ }, [OLD, NEW], LISTING);
+ await page.evaluate(([k, me, old]) => {
+ const st = JSON.parse(localStorage.getItem(k + ':messages') || '{}');
+ st.notifs = [{ id: old.id, what: 'zap', actor: JSON.parse(old.tags.find((t) => t[0] === 'description')[1]).pubkey, target: null, stream: null, hint: [], sats: 10000, text: 'Love it', ts: old.created_at }];
+ st.notifsPk = me; st.notifsV = 2;
+ localStorage.setItem(k + ':messages', JSON.stringify(st));
+ }, [base, ME, OLD]);
+ await page.reload({ waitUntil: 'domcontentloaded' });
+ await waitText('receive', 20000);
+ await page.evaluate(() => document.querySelector('.app-nav-button[aria-label="Notifications"]')?.click());
+ console.log('\n[a zap on your app]');
+ check('a new one reads "zapped your app PAFF"', await waitText('zapped your app paff 2.1k sats', 15000),
+ await page.evaluate(() => [...document.querySelectorAll('.alert-row')].map((r) => r.innerText.replace(/\s+/g, ' ')).join(' | ')));
+ await page.evaluate(() => [...document.querySelectorAll('.alert-row')].find((r) => /great app/.test(r.innerText))?.click());
+ await sleep(300);
+ check('...and opens its Zapstore page', (await page.evaluate(() => window.__opened)).includes('https://zapstore.dev/apps/club.paff.app'), JSON.stringify(await page.evaluate(() => window.__opened)));
+ await page.evaluate(() => { window.__opened = []; [...document.querySelectorAll('.alert-row')].find((r) => /Love it/.test(r.innerText))?.click(); });
+ for (let i = 0; i < 40 && !(await page.evaluate(() => window.__opened.length)); i++) await sleep(250);
+ check('a row saved before reads its receipt on tap and opens the app too', (await page.evaluate(() => window.__opened)).includes('https://zapstore.dev/apps/club.paff.app'), JSON.stringify(await page.evaluate(() => window.__opened)));
+ check('...and is labelled as an app zap from then on', await waitText('zapped your app paff 10k sats', 5000));
+ check('still in Notifications, not a profile', await page.evaluate(() => !!document.querySelector('.alert-row')));
+ check('no page errors', errs.length === 0, errs.slice(0, 2).join(' | '));
+} finally { await browser.close(); server.stop(true); }
+console.log(ok ? '\n✅ zaps on your app open the app' : '\n❌ failed');
+process.exit(ok ? 0 : 1);