v1.53.0: fase 1 de la 2.0 — Lightning, Tx0 de Whirlpool, BIP47 y Runes con transacciones reales; CSP estricta
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L5npnUYgSPkAaHkdaeUqBr
This commit is contained in:
Vendored
+1605
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,34 @@
|
||||
// v1.53.0 — la CSP del nodo puede ser «script-src 'self'»: lo construido no
|
||||
// tiene scripts en línea, el código va en app-….js con su «integrity», y no
|
||||
// usa eval ni new Function (que exigirían 'unsafe-eval').
|
||||
//
|
||||
// Necesita vendor/babel.min.js (como construir.js). Uso: node tests/test44.js
|
||||
const { execFileSync } = require("child_process");
|
||||
const crypto = require("crypto");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const raiz = path.join(__dirname, "..");
|
||||
if (!fs.existsSync(path.join(raiz, "vendor", "babel.min.js"))) { console.log("Sin vendor/babel.min.js: no se puede construir; prueba omitida."); process.exit(0); }
|
||||
execFileSync(process.execPath, [path.join(raiz, "construir.js")], { stdio: "ignore" });
|
||||
|
||||
let pass = 0, fail = 0;
|
||||
const ok = (n, c, x) => { console.log(` ${c ? "✓" : "✗"} ${n}`); if (!c && x !== undefined) console.log(" " + x); c ? pass++ : fail++; };
|
||||
const dist = path.join(raiz, "dist");
|
||||
const html = fs.readFileSync(path.join(dist, "dashboard.html"), "utf8");
|
||||
const apps = fs.readdirSync(dist).filter(f => /^app-[0-9a-f]{12}\.js$/.test(f));
|
||||
ok("hay un único app-….js en dist/", apps.length === 1, apps.join(", "));
|
||||
const etiquetas = html.match(/<script\b[^>]*>/g) || [];
|
||||
ok("ningún <script> en línea en dashboard.html", etiquetas.every(e => /\bsrc=/.test(e)) && !/<script\b[^>]*>\s*[^<\s]/.test(html.replace(/<script\b[^>]*src=[^>]*><\/script>/g, "")), etiquetas.join(" "));
|
||||
const m = html.match(/<script src="(app-[0-9a-f]{12}\.js)" integrity="(sha256-[A-Za-z0-9+/=]+)"><\/script>/);
|
||||
ok("dashboard.html carga app-….js con integrity", !!m && m[1] === apps[0]);
|
||||
const codigo = fs.readFileSync(path.join(dist, apps[0]));
|
||||
const sri = "sha256-" + crypto.createHash("sha256").update(codigo).digest("base64");
|
||||
ok("el integrity coincide con el fichero", m && m[2] === sri);
|
||||
ok("el nombre lleva su huella", apps[0].slice(4, 16) === crypto.createHash("sha256").update(codigo).digest("hex").slice(0, 12));
|
||||
const txt = codigo.toString("utf8");
|
||||
ok("sin new Function ni eval( en la app", !/new Function\s*\(/.test(txt) && !/(^|[^.\w$])eval\s*\(/.test(txt));
|
||||
ok("sin atributos on…= en el HTML (manejadores en línea)", !/<[^>]+\son[a-z]+\s*=/i.test(html));
|
||||
const csp = (fs.readFileSync(path.join(raiz, "nginx-txoko-seguridad.conf"), "utf8").match(/^add_header Content-Security-Policy .*$/m) || [""])[0];
|
||||
ok("la CSP del repo es script-src 'self' sin unsafe", /script-src 'self';/.test(csp) && !/unsafe-eval/.test(csp) && !/script-src[^;]*unsafe-inline/.test(csp));
|
||||
console.log(`\n${pass} correctas, ${fail} fallidas`);
|
||||
process.exit(fail ? 1 : 0);
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
// v1.53.0 — transacciones especiales (fase 1 de la 2.0): Lightning, BIP47 y
|
||||
// Runes, con transacciones reales sacadas del nodo el 26-oct
|
||||
// (tests/fixtures/especiales-26oct.json, comprobadas a mano).
|
||||
//
|
||||
// Uso: node tests/test45.js
|
||||
const crypto = require("crypto");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const lines = require("./fuente.js")().split("\n");
|
||||
const cut = (desde, hasta) => {
|
||||
const s = lines.findIndex(l => l.includes(desde));
|
||||
const e = lines.findIndex((l, i) => i > s && l.includes(hasta));
|
||||
if (s === -1 || e === -1) { console.error(`No se localiza «${desde}» en el código de la app`); process.exit(1); }
|
||||
return lines.slice(s, e).join("\n");
|
||||
};
|
||||
const E = new Function(`const C = { green:"g", amber:"a", red:"r", t1:"t1", t2:"t", blue:"b", purple:"p" };
|
||||
const ENTITY_INDEX = new Map(); const OFAC_SET = new Set();
|
||||
${cut("// ── FORMATO: lógica pura", "// ── fin formato")}
|
||||
${cut("function detectWallets", "function analyzeAddress")}
|
||||
return { analyzeTx };`)();
|
||||
const T = JSON.parse(fs.readFileSync(path.join(__dirname, "fixtures", "especiales-26oct.json"), "utf8")).txs;
|
||||
|
||||
let pass = 0, fail = 0;
|
||||
const ok = (n, c, x) => { console.log(` ${c ? "✓" : "✗"} ${n}`); if (!c && x !== undefined) console.log(" " + x); c ? pass++ : fail++; };
|
||||
const ch = (a, id) => a.checks.find(c => c.id === id);
|
||||
const A = {}; for (const [k, tx] of Object.entries(T)) A[k] = E.analyzeTx(tx);
|
||||
|
||||
console.log("=== Los datos son los de la cadena (txid recalculado) ===\n");
|
||||
{
|
||||
const h = b => Buffer.from(b, "hex");
|
||||
const le = (n, bytes) => { const b = Buffer.alloc(bytes); let v = BigInt(n); for (let i = 0; i < bytes; i++) { b[i] = Number(v & 255n); v >>= 8n; } return b; };
|
||||
const cs = n => n < 0xfd ? Buffer.from([n]) : Buffer.concat([Buffer.from([0xfd]), le(n, 2)]);
|
||||
const txid = tx => {
|
||||
const p = [le(tx.version, 4), cs(tx.vin.length)];
|
||||
for (const v of tx.vin) { const ss = h(v.scriptsig || ""); p.push(h(v.txid).reverse(), le(v.vout, 4), cs(ss.length), ss, le(v.sequence, 4)); }
|
||||
p.push(cs(tx.vout.length));
|
||||
for (const o of tx.vout) { const s = h(o.scriptpubkey); p.push(le(o.value, 8), cs(s.length), s); }
|
||||
p.push(le(tx.locktime, 4));
|
||||
const d = crypto.createHash("sha256").update(crypto.createHash("sha256").update(Buffer.concat(p)).digest()).digest();
|
||||
return Buffer.from(d).reverse().toString("hex");
|
||||
};
|
||||
for (const [k, tx] of Object.entries(T)) ok(`${k}`, txid(tx) === tx.txid);
|
||||
}
|
||||
|
||||
console.log("\n=== Lightning ===\n");
|
||||
{
|
||||
const f = A.ln_cierre_forzado_anclas;
|
||||
ok("cierre forzado con anclas: «Cierre forzado» con CERTEZA", ch(f, "lightning")?.label === "Cierre forzado de un canal Lightning" && ch(f, "lightning").certainty === "CERTEZA");
|
||||
ok("…las 330 sats son anclas, no polvo", ch(f, "dust").pass === true && /anclas/.test(ch(f, "dust").label));
|
||||
ok("…sin cambio que buscar", /se cierra un canal/.test(ch(f, "change_detection").label) && ch(f, "change_detection").pass);
|
||||
ok("…no habla de escrow", !/escrow/i.test(JSON.stringify(f.checks.map(c => c.detail))));
|
||||
const s = A.ln_cierre_forzado_sin_anclas;
|
||||
ok("cierre forzado sin anclas: también lo reconoce", ch(s, "lightning")?.label === "Cierre forzado de un canal Lightning");
|
||||
ok("…y no busca un cambio (antes señalaba una pista)", ch(s, "change_detection").pass && !/señal/.test(ch(s, "change_detection").detail));
|
||||
const c = A.ln_cierre_cooperativo;
|
||||
ok("cierre cooperativo: PROBABLE, no CERTEZA", ch(c, "lightning")?.label === "Cierre cooperativo de un canal Lightning" && ch(c, "lightning").certainty === "PROBABLE");
|
||||
ok("…1→2 pero «no es un pago»", ch(c, "peeling").pass === true && /no es un pago/.test(ch(c, "peeling").label));
|
||||
const m = A.multifirma_juntas;
|
||||
ok("6 multifirmas 2 de 2 juntas: NO es un canal", !ch(m, "lightning"));
|
||||
ok("…y sí habla de multifirma", ch(m, "multifirma") && /escrow|custodia/.test(ch(m, "multifirma").detail));
|
||||
ok("apertura de 16.777.215 sats: posible apertura (PROBABLE)", ch(A.ln_apertura_wumbo_no, "lightning")?.certainty === "PROBABLE");
|
||||
ok("apertura de 0,5 BTC: la forma no basta, no lo afirma", !ch(A.ln_apertura_generica, "lightning"));
|
||||
}
|
||||
|
||||
console.log("\n=== BIP47 ===\n");
|
||||
for (const k of ["bip47_1", "bip47_2", "bip47_3"]) {
|
||||
const a = A[k];
|
||||
ok(`${k}: notificación BIP47 con CERTEZA`, ch(a, "bip47")?.certainty === "CERTEZA");
|
||||
ok(`${k}: los 546 sats son el aviso, no polvo`, ch(a, "dust").pass === true && /BIP47/.test(ch(a, "dust").label));
|
||||
ok(`${k}: el OP_RETURN son 80 bytes (antes 81) y dice qué es`, /80 bytes/.test(ch(a, "op_return").detail) && /BIP47/.test(ch(a, "op_return").detail), ch(a, "op_return").detail.slice(0, 120));
|
||||
}
|
||||
|
||||
console.log("\n=== Runes ===\n");
|
||||
{
|
||||
const r = A.runes;
|
||||
ok("el OP_RETURN se reconoce como Runes", /Runes/.test(ch(r, "op_return").detail));
|
||||
ok("las salidas de 330 sats no son «posible envío de polvo»", ch(r, "dust").pass === true && /Runes/.test(ch(r, "dust").label));
|
||||
}
|
||||
|
||||
console.log("\n=== Whirlpool: Tx0 ===\n");
|
||||
{
|
||||
const a = A.tx0_tres, c = ch(a, "tx0");
|
||||
ok("Tx0 con tres premix: reconocido (PROBABLE)", c && c.certainty === "PROBABLE");
|
||||
ok("…con el pool de Ashigaru y la comisión del coordinador", /0,02500000/.test(c.detail) && /coordinador/.test(c.detail) && /Ashigaru/.test(c.detail));
|
||||
ok("…el cambio es la salida que no va a la mezcla ni al coordinador", ch(a, "change_detection").pass === false && /cambio tóxico/.test(ch(a, "change_detection").detail) && a.checks.find(x => x.id === "change_detection").detail.includes("salida 2"));
|
||||
ok("…avisa de que gastarlo con lo mezclado deshace la mezcla", /deshace la mezcla/.test(c.detail));
|
||||
ok("…el OP_RETURN de 64 bytes es el mensaje para el coordinador", /Whirlpool/.test(ch(a, "op_return").detail));
|
||||
ok("…y el monedero: Ashigaru", /Ashigaru \(Tx0/.test(ch(a, "wallet_fingerprint").detail));
|
||||
ok("Tx0 con un solo premix: también", !!ch(A.tx0_uno, "tx0"));
|
||||
const m = A.mezcla_whirlpool;
|
||||
ok("la mezcla en la que entra: Whirlpool de Ashigaru", ch(m, "coinjoin").pass === true && /Whirlpool/.test(ch(m, "coinjoin").detail) && /Ashigaru/.test(ch(m, "wallet_fingerprint").detail));
|
||||
ok("la mezcla no es un Tx0", !ch(m, "tx0"));
|
||||
ok("un OP_RETURN cualquiera (Runes) no es un Tx0", !ch(A.runes, "tx0"));
|
||||
}
|
||||
|
||||
console.log("\n=== Lo que NO se afirma ===\n");
|
||||
{
|
||||
const r = A.redondos_no_coinjoin;
|
||||
ok("dos entradas de 0,05 BTC: no se dice que vengan de un CoinJoin", !/Whirlpool|post-?mix|vienen? de (un )?CoinJoin|salen de una mezcla/i.test(JSON.stringify(r.checks.map(c => c.label + c.detail))));
|
||||
}
|
||||
|
||||
console.log(`\n${pass} correctas, ${fail} fallidas`);
|
||||
process.exit(fail ? 1 : 0);
|
||||
Reference in New Issue
Block a user