// Repro: names_findsatoshi false negatives for ASCII tab/CR/LF in the URL authority. // Requires: node >=18, and bitcoinjs-message for signing (any BIP-137 signer works). import { createRequire } from 'node:module'; import crypto from 'node:crypto'; const require = createRequire(import.meta.url); const msg = require('/home/chicky/earnordie/node_modules/bitcoinjs-message'); const PRIV = crypto.randomBytes(32); // throwaway key, generated at runtime; never reused const API = 'https://findsatoshi.work'; const sign = (m) => msg.sign(m, PRIV, true).toString('base64'); const vectors = [ ['tab in host', 'https://findsatoshi\t.work/'], ['LF in host', 'https://findsatoshi\n.work/'], ['CR in host', 'https://findsatoshi\r.work/'], ['tab before host', 'https://\tfindsatoshi.work/'], ['LF before host', 'https://\nfindsatoshi.work/'], ['CR before host', 'https://\rfindsatoshi.work/'], ['tab in userinfo', 'https://user\tpass@findsatoshi.work/'], ['LF in userinfo', 'https://user\npass@findsatoshi.work/'], ['CR in userinfo', 'https://user\rpass@findsatoshi.work/'], ['FF in userinfo', 'https://user\fpass@findsatoshi.work/'], ['VT in userinfo', 'https://user\u000Bpass@findsatoshi.work/'], ['control: tab in scheme (already fixed)', 'ht\ttps://findsatoshi.work/'], ]; const out = []; for (const [label, message] of vectors) { const signature = sign(message); const q = new URLSearchParams({ message, signature }); const get = await fetch(`${API}/api/genesis/verify?${q}`).then(r => r.json()); const post = await fetch(`${API}/api/genesis/verify`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ message, signature }), }).then(r => r.json()); let whatwg; try { whatwg = new URL(message).host; } catch (e) { whatwg = `THROW(${e.code || e.message})`; } out.push({ label, message, whatwg_host: whatwg, GET: { valid_signature: get.valid_signature, names_findsatoshi: get.names_findsatoshi }, POST: { valid_signature: post.valid_signature, names_findsatoshi: post.names_findsatoshi } }); } console.log(JSON.stringify({ note: 'WHATWG step 2 removes ASCII tab and newlines from the whole URL input, so every message below parses to host findsatoshi.work. The verifier returns names_findsatoshi=false for the authority positions, although it returns true for the same tab in the scheme.', vectors: out, }, null, 1));