properly handle the case where the (flag-derived) key is invalid (e.g., namely, unpopulated field)
this practically rewrites the JavaScript code in the index.html file now the tool works without manual interventionmain
parent
d2a8c1eba8
commit
c186f2b318
|
@ -21,46 +21,43 @@
|
|||
var inpFlag = document.querySelector("#inp-flag");
|
||||
var outpObscuredFlag = document.querySelector("#outp-obscured-flag");
|
||||
var outpSignature = document.querySelector("#outp-signature");
|
||||
var secp256k1n = new BN('115792089237316195423570985008687907852837564279074904382605163141518161494337', 10);
|
||||
|
||||
function displayObscuredFlag() {
|
||||
var k = inpFlag.value;
|
||||
var t = "0x";
|
||||
for (i in k) {
|
||||
t += k.charCodeAt(i).toString(16).padStart(2, "0");
|
||||
function getPrivateKey() {
|
||||
var s = inpFlag.value;
|
||||
var k = new BN(0);
|
||||
var h = "0x";
|
||||
for (i in s) {
|
||||
var c = s.charCodeAt(i);
|
||||
k = k.muln(16).addn(c);
|
||||
h += c.toString(16).padStart(2, "0");
|
||||
}
|
||||
try {
|
||||
outpObscuredFlag.value = addressFromKey(t);
|
||||
} catch {
|
||||
if (k.mod(secp256k1n).eqn(0)) {
|
||||
return null;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
function updateOutputValues(ev) {
|
||||
var k = getPrivateKey();
|
||||
if (k === null) {
|
||||
outpObscuredFlag.value = "";
|
||||
}
|
||||
}
|
||||
function displaySignature() {
|
||||
var m = inpContestantAddress.value;
|
||||
var k = inpFlag.value;
|
||||
var t = "0x";
|
||||
for (i in k) {
|
||||
t += k.charCodeAt(i).toString(16).padStart(2, "0");
|
||||
}
|
||||
try {
|
||||
outpSignature.value = signMessage(m, t);
|
||||
} catch {
|
||||
outpSignature.value = "";
|
||||
} else {
|
||||
outpObscuredFlag.value = addressFromKey(k);
|
||||
var m = inpContestantAddress.value;
|
||||
if (m.slice(0, 2) !== "0x") {
|
||||
outpSignature.value = "";
|
||||
} else {
|
||||
outpSignature.value = signMessage(m, k);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onContestantAddressChange(ev) {
|
||||
displaySignature();
|
||||
}
|
||||
function onFlagChange(ev) {
|
||||
displayObscuredFlag();
|
||||
displaySignature();
|
||||
}
|
||||
inpContestantAddress.oninput = updateOutputValues;
|
||||
inpFlag.oninput = updateOutputValues;
|
||||
|
||||
inpContestantAddress.oninput = onContestantAddressChange;
|
||||
inpFlag.oninput = onFlagChange;
|
||||
|
||||
displayObscuredFlag();
|
||||
displaySignature();
|
||||
updateOutputValues();
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
|
Loading…
Reference in New Issue