From da498e469782953da78764922001e970b00c6fe6 Mon Sep 17 00:00:00 2001 From: Jeff Weiss Date: Fri, 5 Apr 2013 22:07:16 -0400 Subject: [PATCH 1/6] add secrets.js and some scaffolding --- bitaddress.org.html | 573 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 573 insertions(+) diff --git a/bitaddress.org.html b/bitaddress.org.html index c248936..01aa2fa 100644 --- a/bitaddress.org.html +++ b/bitaddress.org.html @@ -47,6 +47,535 @@ bitaddress.org + + + + @@ -7954,4 +8028,4 @@ setTimeout(ninja.seeder.forceGenerate, ninja.seeder.seedLimit * 20); - \ No newline at end of file + From fa26e7d553e4a695407e5748f30c7d74dc76f6bf Mon Sep 17 00:00:00 2001 From: Jeff Weiss Date: Sat, 6 Apr 2013 22:03:14 -0400 Subject: [PATCH 3/6] 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. --- bitaddress.org.html | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/bitaddress.org.html b/bitaddress.org.html index f7934a5..3bbc19c 100644 --- a/bitaddress.org.html +++ b/bitaddress.org.html @@ -707,12 +707,15 @@ hex.push((bytes[i] >>> 4).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 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)); return bytes; }, @@ -7513,8 +7516,8 @@ var threshhold = parseInt(document.getElementById('splitthreshhold').value); //alert(numshares) //alert(threshhold) - var shares = secrets.share(ninja.publicKey.getHexFromByteArray(Bitcoin.Base58.decode(privkeyBase58)), - numshares, threshhold).map(Crypto.util.hexToBytes).map(Bitcoin.Base58.encode);= + var shares = secrets.share(Crypto.util.bytesToHex(Bitcoin.Base58.decode(privkeyBase58)), + numshares, threshhold).map(Crypto.util.hexToBytes).map(Bitcoin.Base58.encode); //alert(shares); var output = document.createElement("div"); output.setAttribute("id", "splitoutput"); @@ -7542,10 +7545,10 @@ if (element != null) element.parentNode.removeChild(element); var shares = document.getElementById("combineinput").value.split(/\W+/); - alert(shares); + var combined = secrets.combine(shares.map(Bitcoin.Base58.decode). - map(ninja.publicKey.getHexFromByteArray)); - alert(combined); + map(Crypto.util.bytesToHex)); + var privkeyBase58 = Bitcoin.Base58.encode(Crypto.util.hexToBytes(combined)); var output = document.createElement("div"); output.setAttribute("id", "combineoutput"); @@ -7553,6 +7556,9 @@ txt.setAttribute("id","combineoutputtext"); txt.setAttribute("value",privkeyBase58); txt.setAttribute("size",55); + var lbl = document.createElement("label"); + lbl.innerHTML="Private key"; + output.appendChild(lbl); output.appendChild(txt); document.getElementById("combinecommands").appendChild(output); } From 2b5ca8a5f3c0202f9b905b0ef8746d57c66ce912 Mon Sep 17 00:00:00 2001 From: Jeff Weiss Date: Sat, 6 Apr 2013 23:07:30 -0400 Subject: [PATCH 4/6] Fixed hex/bytes conversion so that unit tests still pass. --- bitaddress.org.html | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bitaddress.org.html b/bitaddress.org.html index 3bbc19c..70ce57a 100644 --- a/bitaddress.org.html +++ b/bitaddress.org.html @@ -707,7 +707,7 @@ hex.push((bytes[i] >>> 4).toString(16)); hex.push((bytes[i] & 0xF).toString(16)); } - return hex.join("").split(/^0+/).slice(-1)[0]; //drop leading 0 + return hex.join(""); }, // Convert a hex string to a byte array @@ -7505,6 +7505,8 @@ }, + stripLeadZeros: function(hex) { return hex.split(/^0+/).slice(-1)[0]; }, + // Split a private key and update information in the HTML splitKey: function () { try { @@ -7547,7 +7549,8 @@ var shares = document.getElementById("combineinput").value.split(/\W+/); var combined = secrets.combine(shares.map(Bitcoin.Base58.decode). - map(Crypto.util.bytesToHex)); + map(Crypto.util.bytesToHex). + map(this.stripLeadZeros)); var privkeyBase58 = Bitcoin.Base58.encode(Crypto.util.hexToBytes(combined)); var output = document.createElement("div"); From 04e07e6def48442968c5a8c2cbf19d201d61ad7f Mon Sep 17 00:00:00 2001 From: Jeff Weiss Date: Sun, 28 Apr 2013 17:35:04 -0400 Subject: [PATCH 5/6] Add qr codes to split wallet, also now only generate new keys instead of accepting pasted keys generated elsewhere. --- bitaddress.org.html | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/bitaddress.org.html b/bitaddress.org.html index 70ce57a..326984b 100644 --- a/bitaddress.org.html +++ b/bitaddress.org.html @@ -6321,16 +6321,15 @@
-
- -
+
+
- +
@@ -7490,17 +7489,17 @@ document.getElementById("splitarea").style.display = "none"; }, - mkOutputRow: function(s,n) { + mkOutputRow: function(s,id,lbltxt) { var row = document.createElement("span"); var label = document.createElement("label"); - label.innerHTML="Share " + (n+1); - var txt = document.createElement("input"); - txt.setAttribute("readOnly", true); - txt.setAttribute("value", s); - txt.setAttribute("size", 60); + label.innerHTML= lbltxt + s; + var qr = document.createElement("div"); + + qr.setAttribute("id", id); row.appendChild(label); - row.appendChild(txt); + row.appendChild(qr); row.appendChild(document.createElement("br")); + return row; }, @@ -7510,24 +7509,32 @@ // Split a private key and update information in the HTML splitKey: function () { try { + var key = new Bitcoin.ECKey(false); + var bitcoinAddress = key.getBitcoinAddress(); var element = document.getElementById("splitoutput"); if (element != null) element.parentNode.removeChild(element); - var privkeyBase58 = document.getElementById('splitprivkey').value; var numshares = parseInt(document.getElementById('splitshares').value); var threshhold = parseInt(document.getElementById('splitthreshhold').value); //alert(numshares) //alert(threshhold) - var shares = secrets.share(Crypto.util.bytesToHex(Bitcoin.Base58.decode(privkeyBase58)), + var shares = secrets.share(Crypto.util.bytesToHex(key.getBitcoinPrivateKeyByteArray()), numshares, threshhold).map(Crypto.util.hexToBytes).map(Bitcoin.Base58.encode); //alert(shares); var output = document.createElement("div"); output.setAttribute("id", "splitoutput"); + var m = {}; + output.appendChild(this.mkOutputRow(bitcoinAddress, "split_addr", "Bitcoin Address: ")); + m["split_addr"] = bitcoinAddress; + for (var i=0; i < shares.length; i++) { - output.appendChild(this.mkOutputRow(shares[i], i)); + var id = "split_qr_"+ i; + output.appendChild(this.mkOutputRow(shares[i], id, "Share " + (i+1) + ": ")); + m[id]=shares[i]; } document.getElementById("splitcommands").appendChild(output); + ninja.qrCode.showQrCode(m); } catch (e) { @@ -7552,7 +7559,7 @@ map(Crypto.util.bytesToHex). map(this.stripLeadZeros)); - var privkeyBase58 = Bitcoin.Base58.encode(Crypto.util.hexToBytes(combined)); + var privkeyBase58 = new Bitcoin.ECKey(Crypto.util.hexToBytes(combined)).getBitcoinWalletImportFormat(); var output = document.createElement("div"); output.setAttribute("id", "combineoutput"); var txt = document.createElement("input"); From e555680e1cdfb7a9250ddea78f28e6fe0a8703cd Mon Sep 17 00:00:00 2001 From: Jeff Weiss Date: Mon, 29 Apr 2013 10:43:24 -0400 Subject: [PATCH 6/6] Update README and attempt to fix whitespace. --- README | 1 + bitaddress.org.html | 158 +++++++++++++++++++++----------------------- 2 files changed, 77 insertions(+), 82 deletions(-) diff --git a/README b/README index 93057f5..63d9f8d 100644 --- a/README +++ b/README @@ -49,6 +49,7 @@ window.EllipticCurve BSD License window.BigInteger BSD License window.QRCode MIT License window.Bitcoin MIT License +window.secrets MIT Licenses The bitaddress.org software is available under The MIT License (MIT) Copyright (c) 2011-2012 bitaddress.org diff --git a/bitaddress.org.html b/bitaddress.org.html index 326984b..c45a8a9 100644 --- a/bitaddress.org.html +++ b/bitaddress.org.html @@ -7477,65 +7477,59 @@