This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkDevTools() { | |
// TODO: hacer cosas | |
// Preparar la siguiente ejecución | |
setTimeout(checkDevTools, 250); | |
} | |
checkDevTools(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Iniciar cronómetro | |
var time_start = (new Date()).getTime(); | |
// Pausar ejecución | |
debugger; | |
// Parar cronómetro | |
var time_end = (new Date()).getTime(); | |
var diff = time_end - time_start; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Detectar Developer Tools abierto | |
var tolerance = 300; | |
var dev_open = (diff > tolerance); | |
// Mostrar mensaje de error | |
if (dev_open) { | |
document.body.innerHTML = 'Cierra las Developer Tools y recarga la web'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static KeyPair generateKeyPair() { | |
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA"); | |
kpg.initialize(1024); | |
return kpg.genKeyPair(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String keyToBase64(Key key) { | |
return Base64.getEncoder().encodeToString(key.getEncoded()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private final PublicKey from; | |
private final PublicKey to; | |
private final float amount; | |
private final Date timestamp; | |
private byte[] signature = null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean sign(PrivateKey pk) { | |
// Comprobar que no está firmada la transacción | |
if (signature != null) return false; | |
// Comprobar que la clave privada se corresponde con esta transacción | |
PublicKey expected = getPublicFromPrivate(pk); | |
if (!expected.equals(from)) return false; | |
// Intentar firmar la transacción | |
try { | |
Signature sig = Signature.getInstance("SHA1WithRSA"); | |
// Especificar clave privada |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public float getBalance(PublicKey addr) { | |
float balance = 0; | |
for (Block b : chain) { | |
// Añadir saldo de transacciones | |
for (Transaction t : b.getTransactions()) { | |
if (addr.equals(t.getFrom())) { | |
// En caso de ser el pagador | |
balance -= t.getAmount(); | |
} else if (addr.equals(t.getTo())) { | |
// En caso de ser el receptor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private final long index; | |
private final ArrayList<Transaction> transactions; | |
private long nonce = 0; | |
private String hash; | |
private final String previous_hash; | |
private final PublicKey miner; | |
private final float fee; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void mine() { | |
while (!isValidHash()) { | |
nonce++; | |
recalculateHash(); | |
} | |
} |