Files
txoko-dashboard/tests/extraer-cripto.js
T

28 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Extrae del código de la app el bloque «BIP32 / bech32» —la criptografía de la
// derivación watch-only— y lo devuelve a las pruebas test1–test4.
//
// Igual que el resto de pruebas, lee el código de la app tal como está, no una
// copia, así que no se desactualiza. Hasta el 2026-10-20 estas cuatro dependían
// de un crypto.js extraído a mano en /tmp que ya no existía: no se podían
// ejecutar, y la parte más delicada de la app era la peor vigilada.
//
// TXOKO_HTML permite apuntar a otro dashboard.html (por ejemplo, una copia con
// un fallo metido a propósito, para comprobar que las pruebas lo detectan).
const fs = require("fs");
const path = require("path");
if (!globalThis.crypto) globalThis.crypto = require("crypto").webcrypto;
const htmlPath = process.env.TXOKO_HTML || "el código de la app (src/)";
const lines = require("./fuente.js")().split("\n");
const desde = "// ── BIP32 / bech32", hasta = "// ── Informe de wallet completo";
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 el bloque «BIP32 / bech32» en ${htmlPath}`);
process.exit(1);
}
module.exports = new Function(lines.slice(s, e).join("\n") +
"\nreturn { B32, SECP, deriveChildPubkey, ripemd160, hash160, toBech32, deriveAddresses, XPUB_VERSIONS };")();