diff options
| author | Adam Soltys <[email protected]> | 2026-11-23 09:22:47 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-11-23 09:22:47 -0700 |
| commit | 2cd42f811d33a74c3ca28094176c009c0388da9b (patch) | |
| tree | b2b4127f00cbd7fef990596e7f92511dbf308380 /tools | |
| parent | 7711115f1e2a7f8cd73017d548274d4fab9f3d86 (diff) | |
| download | coinosv3-2cd42f811d33a74c3ca28094176c009c0388da9b.tar.gz coinosv3-2cd42f811d33a74c3ca28094176c009c0388da9b.zip | |
A coinos name has a public pay page: v3.coinos.io/<name>/receive. "The old Coinos I could point this link onto my website give people the ability to Donate/Pay in Bitcoin and Lighting - https://coinos.io/JuryImagePro/receive - I'm not seeing an option to do this thru V3, am I missing something?" (JuryImagePro, relayed by Adam 2026-11-23). v3 had no page a visitor could pay a name from: tapping pay on a profile asks a visitor to sign in. /<name>/receive and /<name>/pay now open a small page of their own (dist/pay/index.html from src/pay-page.js, 39 KB, not the app): the name's face, a LNURL QR any Lightning wallet can pay with an amount picked there, the address to copy, and a form for a set amount and a note that makes an invoice (QR, copy, open in wallet). When coinos' node minted the invoice the page says Paid once it settles (LUD-21 verify, coinosv3-server e40c5eb); when the recipient's own wallet minted it, the page says to pay it from the wallet. ?amount= fills in the amount. Lightning only: a v3 name publishes no on-chain address. Receive → More options → Payment page shows the link with Copy and Open page. nginx on cs routes the two paths to the page; the service worker leaves them alone. New pay-page-test (set amount + note, Paid, no-verify invoice, minimum, unknown name) and names-pay-page-link-test pass; names-invoice-expiry, features-smoke and feature-registry-check pass.HEADmaster
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VMan6Upic5L6MMJzkTn8zg
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/names-pay-page-link-test.js | 58 | ||||
| -rw-r--r-- | tools/pay-page-test.js | 84 |
2 files changed, 142 insertions, 0 deletions
diff --git a/tools/names-pay-page-link-test.js b/tools/names-pay-page-link-test.js new file mode 100644 index 0000000..5e18a43 --- /dev/null +++ b/tools/names-pay-page-link-test.js @@ -0,0 +1,58 @@ +// Receive → More options → Payment page: the link to the name's public pay +// page (v3.coinos.io/<name>/receive, see pay-page-test), to copy or open. +// Run: bun tools/names-pay-page-link-test.js +import assert from 'node:assert/strict'; +import puppeteer from './puppeteer.js'; + +const app = await Bun.file('src/app.js').text(); +const domHelper = app.slice(app.indexOf('function h(tag,'), app.indexOf('// ---------------------------------------------------------------- morphing')); +const entry = ` +import { namesFeature } from './src/features/names.js'; +${domHelper} +const state = { names: { byDomain: { 'coinos.io': { name: 'alice', domain: 'coinos.io' } } } }; +const ui = { screen: 'wallet', namesMore: 'menu' }; +const wallet = { loadFeatureState: (k, d) => (k in state ? state[k] : d), saveFeatureState: (k, v) => { state[k] = v; }, nostrSign: async (e) => e, nostrPubkey: () => 'aa'.repeat(32), _cacheKey: () => 'w1' }; +const ctx = { + h, ui, wallet, render, toast: () => {}, copy: () => {}, copyBtn: (x, l) => h('button', { class: 'btn-sm' }, l), brandHeader: () => null, goBack: () => {}, setAccount: () => {}, + hook(name, ...a) { + if (name === 'arkReady') return true; + if (name === 'arkMakeInvoice') return Promise.resolve({ invoice: 'lnbc10u1testinvoice', amountSat: a[0], expiresAt: Date.now() + (window.__life || 3600_000) }); + return null; + }, +}; +const feature = namesFeature(ctx); +function render() { document.querySelector('#app').replaceChildren(feature.receiveModes()[0].render(h('div', { class: 'seg' }))); } +window.test = { render }; +render(); +`; +const bundle = await Bun.build({ + entrypoints: ['names-page-entry'], target: 'browser', + plugins: [{ name: 'names-page', setup(build) { + build.onResolve({ filter: /^names-page-entry$/ }, () => ({ path: 'entry', namespace: 'names-page' })); + build.onLoad({ filter: /.*/, namespace: 'names-page' }, () => ({ contents: entry, loader: 'js', resolveDir: process.cwd() })); + } }], +}); +assert(bundle.success, bundle.logs.join('\n')); +const html = `<!doctype html><meta charset="utf-8"><style>${await Bun.file('src/style.css').text()}</style><div id="app"></div><script type="module">${await bundle.outputs[0].text()}</script>`; +const server = Bun.serve({ port: 0, fetch: () => new Response(html, { headers: { 'content-type': 'text/html' } }) }); +const browser = await puppeteer.launch({ executablePath: '/usr/bin/google-chrome', headless: true, args: ['--no-sandbox'] }); +const page = await browser.newPage(); +const errors = []; +page.on('pageerror', (e) => errors.push(e.message)); +const pause = (ms) => new Promise((r) => setTimeout(r, ms)); +const check = (name, value, detail = '') => { assert(value, name + (detail ? ' — ' + detail : '')); console.log(' ✓ ' + name); }; +const text = () => page.evaluate(() => document.body.innerText.replace(/\s+/g, ' ')); +try { + await page.goto(server.url.href); + await page.waitForFunction(() => /Payment page/.test(document.body.innerText)); + check('More options lists the payment page', /A link for your website/.test(await text())); + await page.evaluate(() => [...document.querySelectorAll('.item')].find((d) => /Payment page/.test(d.textContent)).click()); + await pause(50); + check('...which shows the link for this name', /https:\/\/v3\.coinos\.io\/alice\/receive/.test(await text()), await text()); + check('...with Copy and Open page', await page.evaluate(() => ['Copy', 'Open page'].every((l) => [...document.querySelectorAll('button')].some((b) => b.textContent.trim() === l)))); + check('no page errors', !errors.length, errors.join(' | ')); + console.log('\n✅ the payment page link is in More options'); +} finally { + await browser.close(); + server.stop(true); +} diff --git a/tools/pay-page-test.js b/tools/pay-page-test.js new file mode 100644 index 0000000..c463959 --- /dev/null +++ b/tools/pay-page-test.js @@ -0,0 +1,84 @@ +// v3.coinos.io/<name>/receive: a visitor pays a coinos name over Lightning +// from a page of its own (no wallet on this site). The registrar is faked. +// Run: bun tools/pay-page-test.js +import assert from 'node:assert/strict'; +import puppeteer from './puppeteer.js'; +import { buildPayPage } from '../build.js'; + +const page_ = await buildPayPage({ minify: true }); +const server = Bun.serve({ port: 0, fetch() { return new Response(page_, { headers: { 'Content-Type': 'text/html' } }); } }); +const PR = 'lnbc210n1pjtestinvoiceqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq'; +const PK = 'e21a18f58b31baee9291b295c24cbe7aa1787f141af4c7f513a40b4b80262a20'; +const browser = await puppeteer.launch({ executablePath: '/usr/bin/google-chrome', headless: 'new', args: ['--no-sandbox'] }); +const check = (name, ok, detail = '') => { assert(ok, name + (detail ? ' — ' + detail : '')); console.log(' ✓ ' + name); }; + +async function open(path, { verify = true } = {}) { + const page = await browser.newPage(); + const seen = { cb: [], verify: 0, errors: [] }; + page.on('pageerror', (e) => seen.errors.push(e.message)); + await page.setRequestInterception(true); + page.on('request', (r) => { + const u = new URL(r.url()); + const json = (o, status = 200) => r.respond({ status, contentType: 'application/json', headers: { 'Access-Control-Allow-Origin': '*' }, body: JSON.stringify(o) }); + if (u.origin === server.url.origin) return r.continue(); + if (u.host !== 'names.coinos.io') return r.abort(); + if (u.pathname === '/lnurlp/shopkeeper') return json({ tag: 'payRequest', callback: 'https://names.coinos.io/lnurlp/shopkeeper/cb?domain=coinos.io', minSendable: 1000, maxSendable: 500000000, metadata: '[]', commentAllowed: 200 }); + if (u.pathname === '/name/shopkeeper') return json({ name: 'shopkeeper', taken: true, pubkey: PK }); + if (u.pathname === '/lnurlp/shopkeeper/cb') { seen.cb.push(Object.fromEntries(u.searchParams)); return json({ pr: PR, routes: [], ...(verify ? { verify: 'https://names.coinos.io/lnurlp/verify/' + 'ab'.repeat(32) } : {}) }); } + if (u.pathname.startsWith('/lnurlp/verify/')) { seen.verify++; return json({ status: 'OK', settled: seen.verify >= 2, preimage: null, pr: PR }); } + if (u.pathname.startsWith('/lnurlp/')) return json({ status: 'ERROR', reason: 'unknown address' }, 404); + return r.abort(); + }); + // no relays in the test: the profile lookup just finds nothing + await page.evaluateOnNewDocument(() => { window.WebSocket = class { constructor() { setTimeout(() => this.onerror?.({}), 0); } send() {} close() {} }; }); + await page.goto(server.url.origin + path); + return { page, seen }; +} + +try { + { + const { page, seen } = await open('/ShopKeeper/receive?amount=2100'); + await page.waitForSelector('#amount', { timeout: 5000 }); + const text = await page.evaluate(() => document.body.innerText); + check('the page names the address', text.includes('[email protected]'), text); + const qr = await page.$eval('.qr', (a) => a.getAttribute('href')); + check('...with a QR any Lightning wallet can open (LNURL)', /^lightning:LNURL1[0-9A-Z]+$/.test(qr), qr); + check('...and the amount from the link filled in', (await page.$eval('#amount', (i) => i.value)) === '2100'); + await page.$eval('#amount', (i) => { i.value = '21'; }); + await page.type('#note', 'for the prints'); + await page.click('button.primary'); + await page.waitForSelector('#invoice', { timeout: 5000 }); + check('a set amount asks the registrar for that many msat, with the note', seen.cb.length === 1 && seen.cb[0].amount === '21000' && seen.cb[0].comment === 'for the prints', JSON.stringify(seen.cb)); + const inv = await page.$eval('#invoice .qr', (a) => a.getAttribute('href')); + check('...and shows its invoice as a QR', inv === 'lightning:' + PR.toUpperCase(), inv); + check('...with an open-in-wallet link', (await page.$eval('#invoice a.button', (a) => a.getAttribute('href'))) === 'lightning:' + PR); + await page.waitForSelector('#paid', { timeout: 10000 }); + check('it says Paid once the registrar says the invoice settled', (await page.evaluate(() => document.body.innerText)).includes('21 sats sent to [email protected]')); + check('no page errors', !seen.errors.length, seen.errors.join(' | ')); + await page.close(); + } + { + const { page } = await open('/shopkeeper/pay', { verify: false }); + await page.waitForSelector('#amount', { timeout: 5000 }); + await page.type('#amount', '500'); + await page.click('button.primary'); + await page.waitForSelector('#invoice', { timeout: 5000 }); + check('/pay works too; an invoice nobody can watch says to pay it from the wallet', (await page.$eval('#status', (s) => s.textContent)) === 'Pay it from your Lightning wallet.'); + await page.click('button.link'); + check('...and "another amount" goes back', !!(await page.waitForSelector('#amount', { timeout: 3000 }))); + await page.$eval('#amount', (i) => { i.value = '0'; }); + await page.click('button.primary'); + check('an amount under the minimum is refused on the page', /at least 1 sats/.test(await page.$eval('#err', (e) => e.textContent))); + await page.close(); + } + { + const { page } = await open('/nobody/receive'); + await page.waitForFunction(() => document.querySelector('.err'), { timeout: 5000 }); + check('an unknown name says so', (await page.$eval('.err', (e) => e.textContent)) === '[email protected] is not a coinos address.'); + await page.close(); + } + console.log('\n✅ a coinos name has a pay page'); +} finally { + await browser.close(); + server.stop(true); +} |
