Split/combine appear to be working correctly. Had to change conversion between bytes and hex to handle odd-numbers of hex characters. Seems to have been misbehaving.
This commit is contained in:
parent
e38301be98
commit
fa26e7d553
1 changed files with 13 additions and 7 deletions
|
@ -707,12 +707,15 @@
|
||||||
hex.push((bytes[i] >>> 4).toString(16));
|
hex.push((bytes[i] >>> 4).toString(16));
|
||||||
hex.push((bytes[i] & 0xF).toString(16));
|
hex.push((bytes[i] & 0xF).toString(16));
|
||||||
}
|
}
|
||||||
return hex.join("");
|
return hex.join("").split(/^0+/).slice(-1)[0]; //drop leading 0
|
||||||
},
|
},
|
||||||
|
|
||||||
// Convert a hex string to a byte array
|
// Convert a hex string to a byte array
|
||||||
hexToBytes: function (hex) {
|
hexToBytes: function (hex) {
|
||||||
for (var bytes = [], c = 0; c < hex.length; c += 2)
|
//if input has odd number of digits, pad it
|
||||||
|
if (hex.length % 2 == 1)
|
||||||
|
hex = "0" + hex;
|
||||||
|
for (var bytes = [], c = 0; c < hex.length; c += 2)
|
||||||
bytes.push(parseInt(hex.substr(c, 2), 16));
|
bytes.push(parseInt(hex.substr(c, 2), 16));
|
||||||
return bytes;
|
return bytes;
|
||||||
},
|
},
|
||||||
|
@ -7513,8 +7516,8 @@
|
||||||
var threshhold = parseInt(document.getElementById('splitthreshhold').value);
|
var threshhold = parseInt(document.getElementById('splitthreshhold').value);
|
||||||
//alert(numshares)
|
//alert(numshares)
|
||||||
//alert(threshhold)
|
//alert(threshhold)
|
||||||
var shares = secrets.share(ninja.publicKey.getHexFromByteArray(Bitcoin.Base58.decode(privkeyBase58)),
|
var shares = secrets.share(Crypto.util.bytesToHex(Bitcoin.Base58.decode(privkeyBase58)),
|
||||||
numshares, threshhold).map(Crypto.util.hexToBytes).map(Bitcoin.Base58.encode);=
|
numshares, threshhold).map(Crypto.util.hexToBytes).map(Bitcoin.Base58.encode);
|
||||||
//alert(shares);
|
//alert(shares);
|
||||||
var output = document.createElement("div");
|
var output = document.createElement("div");
|
||||||
output.setAttribute("id", "splitoutput");
|
output.setAttribute("id", "splitoutput");
|
||||||
|
@ -7542,10 +7545,10 @@
|
||||||
if (element != null) element.parentNode.removeChild(element);
|
if (element != null) element.parentNode.removeChild(element);
|
||||||
|
|
||||||
var shares = document.getElementById("combineinput").value.split(/\W+/);
|
var shares = document.getElementById("combineinput").value.split(/\W+/);
|
||||||
alert(shares);
|
|
||||||
var combined = secrets.combine(shares.map(Bitcoin.Base58.decode).
|
var combined = secrets.combine(shares.map(Bitcoin.Base58.decode).
|
||||||
map(ninja.publicKey.getHexFromByteArray));
|
map(Crypto.util.bytesToHex));
|
||||||
alert(combined);
|
|
||||||
var privkeyBase58 = Bitcoin.Base58.encode(Crypto.util.hexToBytes(combined));
|
var privkeyBase58 = Bitcoin.Base58.encode(Crypto.util.hexToBytes(combined));
|
||||||
var output = document.createElement("div");
|
var output = document.createElement("div");
|
||||||
output.setAttribute("id", "combineoutput");
|
output.setAttribute("id", "combineoutput");
|
||||||
|
@ -7553,6 +7556,9 @@
|
||||||
txt.setAttribute("id","combineoutputtext");
|
txt.setAttribute("id","combineoutputtext");
|
||||||
txt.setAttribute("value",privkeyBase58);
|
txt.setAttribute("value",privkeyBase58);
|
||||||
txt.setAttribute("size",55);
|
txt.setAttribute("size",55);
|
||||||
|
var lbl = document.createElement("label");
|
||||||
|
lbl.innerHTML="Private key";
|
||||||
|
output.appendChild(lbl);
|
||||||
output.appendChild(txt);
|
output.appendChild(txt);
|
||||||
document.getElementById("combinecommands").appendChild(output);
|
document.getElementById("combinecommands").appendChild(output);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue