diff --git a/bitaddress.org.html b/bitaddress.org.html
index cf4bee4..f9ecaa7 100644
--- a/bitaddress.org.html
+++ b/bitaddress.org.html
@@ -25,7 +25,7 @@
window.Bitcoin MIT License
The bitaddress.org software is available under The MIT License (MIT)
- Copyright (c) 2011 bitaddress.org
+ Copyright (c) 2011-2012 bitaddress.org
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction, including
@@ -948,24 +948,25 @@
};
// patched by bitaddress.org and Casascius for use with Bitcoin.ECKey
+ // patched by coretechs to support compressed public keys
ec.PointFp.prototype.getEncoded = function (compressed) {
var x = this.getX().toBigInteger();
var y = this.getY().toBigInteger();
var len = 32; // integerToBytes will zero pad if integer is less than 32 bytes. 32 bytes length is required by the Bitcoin protocol.
var enc = ec.integerToBytes(x, len);
- // modded from old code from forum post
+ // when compressed prepend byte depending if y point is even or odd
if (compressed) {
if (y.isEven()) {
enc.unshift(0x02);
- }
+ }
else {
enc.unshift(0x03);
- }
- }
+ }
+ }
else {
enc.unshift(0x04);
- enc = enc.concat(ec.integerToBytes(y, len));
+ enc = enc.concat(ec.integerToBytes(y, len)); // uncompressed public key appends the bytes of the y point
}
return enc;
};
@@ -3742,75 +3743,97 @@
}
};
- ECKey.prototype.getPub = function (compressed) {
- //if (this.pub) return this.pub;
- this.pub = ecparams.getG().multiply(this.priv).getEncoded(compressed);
- return this.pub;
+ ECKey.prototype.getPub = function () {
+ if (this.pub) return this.pub;
+ return this.pub = ecparams.getG().multiply(this.priv).getEncoded(0);
};
- ECKey.prototype.getPubKeyHash = function (compressed) {
- //if (this.pubKeyHash) return this.pubKeyHash;
- return this.pubKeyHash = Bitcoin.Util.sha256ripe160(this.getPub(compressed));
+ ECKey.prototype.getPubCompressed = function () {
+ if (this.pubCompressed) return this.pubCompressed;
+ return this.pubCompressed = ecparams.getG().multiply(this.priv).getEncoded(1);
};
- ECKey.prototype.getBitcoinAddress = function (compressed) {
- var hash = this.getPubKeyHash(compressed);
+ ECKey.prototype.getPubKeyHash = function () {
+ if (this.pubKeyHash) return this.pubKeyHash;
+ return this.pubKeyHash = Bitcoin.Util.sha256ripe160(this.getPub());
+ };
+
+ ECKey.prototype.getPubKeyHashCompressed = function () {
+ if (this.pubKeyHashCompressed) return this.pubKeyHashCompressed;
+ return this.pubKeyHashCompressed = Bitcoin.Util.sha256ripe160(this.getPubCompressed());
+ };
+
+ ECKey.prototype.getBitcoinAddress = function () {
+ var hash = this.getPubKeyHash();
var addr = new Bitcoin.Address(hash);
return addr.toString();
};
- // Sipa Private Key Wallet Import Format (added by bitaddress.org)
- ECKey.prototype.getBitcoinWalletImportFormat = function (compressed) {
- // Get a copy of private key as a byte array
- var bytes = this.priv.toByteArrayUnsigned();
-
- // zero pad if private key is less than 32 bytes (thanks Casascius)
- while (bytes.length < 32) bytes.unshift(0x00);
+ ECKey.prototype.getBitcoinAddressCompressed = function () {
+ var hash = this.getPubKeyHashCompressed();
+ var addr = new Bitcoin.Address(hash);
+ return addr.toString();
+ };
+ // Sipa Private Key Wallet Import Format
+ ECKey.prototype.getBitcoinWalletImportFormat = function () {
+ var bytes = this.getBitcoinPrivateKeyByteArray();
bytes.unshift(0x80); // prepend 0x80 byte
-
- if (compressed) {
- bytes.push(0x01); // append 0x01 byte for compressed format
- }
-
var checksum = Crypto.SHA256(Crypto.SHA256(bytes, { asBytes: true }), { asBytes: true });
bytes = bytes.concat(checksum.slice(0, 4));
-
var privWif = Bitcoin.Base58.encode(bytes);
return privWif;
};
- // Private Key Hex Format (added by bitaddress.org)
+ // Sipa Private Key Wallet Import Format Compressed
+ ECKey.prototype.getBitcoinWalletImportFormatCompressed = function () {
+ var bytes = this.getBitcoinPrivateKeyByteArray();
+ bytes.unshift(0x80); // prepend 0x80 byte
+ bytes.push(0x01); // append 0x01 byte for compressed format
+ var checksum = Crypto.SHA256(Crypto.SHA256(bytes, { asBytes: true }), { asBytes: true });
+ bytes = bytes.concat(checksum.slice(0, 4));
+ var privWifComp = Bitcoin.Base58.encode(bytes);
+ return privWifComp;
+ };
+
+ // Private Key Hex Format
ECKey.prototype.getBitcoinHexFormat = function () {
+ return Crypto.util.bytesToHex(this.getBitcoinPrivateKeyByteArray()).toString().toUpperCase();
+ };
+
+ // Private Key Base64 Format
+ ECKey.prototype.getBitcoinBase64Format = function () {
+ return Crypto.util.bytesToBase64(this.getBitcoinPrivateKeyByteArray());
+ };
+
+ ECKey.prototype.getBitcoinPrivateKeyByteArray = function () {
// Get a copy of private key as a byte array
var bytes = this.priv.toByteArrayUnsigned();
// zero pad if private key is less than 32 bytes
while (bytes.length < 32) bytes.unshift(0x00);
-
- return Crypto.util.bytesToHex(bytes).toString().toUpperCase();
+ return bytes;
};
-
ECKey.prototype.setPub = function (pub) {
this.pub = pub;
};
+ ECKey.prototype.setPubCompressed = function (pubCompressed) {
+ this.pubCompressed = pubCompressed;
+ };
+
ECKey.prototype.toString = function (format) {
format = format || "";
- // Get a copy of private key as a byte array
- var bytes = this.priv.toByteArrayUnsigned();
- // zero pad if private key is less than 32 bytes
- while (bytes.length < 32) bytes.unshift(0x00);
- if (format === "base64" || format === "b64") {
- return Crypto.util.bytesToBase64(bytes);
+ if (format.toString().toLowerCase() == "base64" || format.toString().toLowerCase() == "b64") {
+ return this.getBitcoinBase64Format();
}
// Wallet Import Format
else if (format.toString().toLowerCase() == "wif") {
- return this.getBitcoinWalletImportFormat(0);
+ return this.getBitcoinWalletImportFormat();
}
else if (format.toString().toLowerCase() == "wifcomp") {
- return this.getBitcoinWalletImportFormat(1);
+ return this.getBitcoinWalletImportFormatCompressed();
}
else {
return this.getBitcoinHexFormat();
@@ -3822,7 +3845,7 @@
};
ECKey.prototype.verify = function (hash, sig) {
- return ECDSA.verify(hash, sig, this.getPub(0));
+ return ECDSA.verify(hash, sig, this.getPub());
};
return ECKey;
@@ -4005,7 +4028,7 @@
}
-
+
@@ -4083,7 +4106,7 @@
- Your Bitcoin Private Key is a unique secret number that only you know. It can be be encoded in a number of different formats.
+ Your Bitcoin Private Key is a unique secret number that only you know. It can be encoded in a number of different formats.
Below we show the Bitcoin Address and Public Key that corresponds to your Private Key as well as your Private Key in the most popular encoding formats (WIF, HEX, B64, MINI).
@@ -4201,7 +4224,7 @@
Copyright bitaddress.org.
@@ -4219,8 +4242,8 @@
idPostFix = idPostFix || "";
try {
var key = new Bitcoin.ECKey(false);
- var bitcoinAddress = key.getBitcoinAddress(0);
- var privateKeyWif = key.getBitcoinWalletImportFormat(0);
+ var bitcoinAddress = key.getBitcoinAddress();
+ var privateKeyWif = key.getBitcoinWalletImportFormat();
}
catch (e) {
alert(e);
@@ -4443,7 +4466,7 @@
var key = new Bitcoin.ECKey(false);
bulkWallet.csv.push((bulkWallet.csvRowLimit - bulkWallet.csvRowsRemaining + bulkWallet.csvStartIndex)
- + ",\"" + key.getBitcoinAddress(0) + "\",\"" + key.toString("wif")
+ + ",\"" + key.getBitcoinAddress() + "\",\"" + key.toString("wif")
//+ "\",\"" + key.toString("wifcomp") // uncomment these lines to add different private key formats to the CSV
//+ "\",\"" + key.getBitcoinHexFormat()
//+ "\",\"" + key.toString("base64")
@@ -4680,17 +4703,17 @@
}
if (btcKey != undefined) {
- var pubKey = Crypto.util.bytesToHex(btcKey.getPub(0)).toUpperCase();
- var pubKeyComp = Crypto.util.bytesToHex(btcKey.getPub(1)).toUpperCase();
+ var pubKey = Crypto.util.bytesToHex(btcKey.getPub()).toUpperCase();
+ var pubKeyComp = Crypto.util.bytesToHex(btcKey.getPubCompressed()).toUpperCase();
var halfWayIndex = Math.floor(pubKey.length / 2);
var pubKeyFirstHalf = pubKey.substr(0, halfWayIndex);
var pubKeySecondHalf = pubKey.substr(halfWayIndex, pubKey.length - halfWayIndex);
document.getElementById("detailpubkey").innerHTML = pubKeyFirstHalf + "
" + pubKeySecondHalf;
document.getElementById("detailpubkeycomp").innerHTML = pubKeyComp;
- document.getElementById("detailaddress").innerHTML = btcKey.getBitcoinAddress(0);
- document.getElementById("detailaddresscomp").innerHTML = btcKey.getBitcoinAddress(1);
- document.getElementById("detailprivwif").innerHTML = btcKey.getBitcoinWalletImportFormat(0);
- document.getElementById("detailprivwifcomp").innerHTML = btcKey.getBitcoinWalletImportFormat(1);
+ document.getElementById("detailaddress").innerHTML = btcKey.getBitcoinAddress();
+ document.getElementById("detailaddresscomp").innerHTML = btcKey.getBitcoinAddressCompressed();
+ document.getElementById("detailprivwif").innerHTML = btcKey.getBitcoinWalletImportFormat();
+ document.getElementById("detailprivwifcomp").innerHTML = btcKey.getBitcoinWalletImportFormatCompressed();
document.getElementById("detailprivhex").innerHTML = btcKey.toString().toUpperCase();
document.getElementById("detailprivb64").innerHTML = btcKey.toString("base64");
document.getElementById("detailqrcodepublic").innerHTML = "";
@@ -4699,17 +4722,17 @@
document.getElementById("detailqrcodeprivatecomp").innerHTML = "";
// show QR codes
try {
- document.getElementById("detailqrcodepublic").appendChild(ninja.qrCode.createCanvas(btcKey.getBitcoinAddress(0)));
- document.getElementById("detailqrcodepubliccomp").appendChild(ninja.qrCode.createCanvas(btcKey.getBitcoinAddress(1)));
- document.getElementById("detailqrcodeprivate").appendChild(ninja.qrCode.createCanvas(btcKey.getBitcoinWalletImportFormat(0)));
- document.getElementById("detailqrcodeprivatecomp").appendChild(ninja.qrCode.createCanvas(btcKey.getBitcoinWalletImportFormat(1)));
+ document.getElementById("detailqrcodepublic").appendChild(ninja.qrCode.createCanvas(btcKey.getBitcoinAddress()));
+ document.getElementById("detailqrcodepubliccomp").appendChild(ninja.qrCode.createCanvas(btcKey.getBitcoinAddressCompressed()));
+ document.getElementById("detailqrcodeprivate").appendChild(ninja.qrCode.createCanvas(btcKey.getBitcoinWalletImportFormat()));
+ document.getElementById("detailqrcodeprivatecomp").appendChild(ninja.qrCode.createCanvas(btcKey.getBitcoinWalletImportFormatCompressed()));
}
catch (e) {
// for browsers that do not support canvas (IE8)
- document.getElementById("detailqrcodepublic").innerHTML = ninja.qrCode.createTableHtml(btcKey.getBitcoinAddress(0));
- document.getElementById("detailqrcodepubliccomp").innerHTML = ninja.qrCode.createTableHtml(btcKey.getBitcoinAddress(1));
- document.getElementById("detailqrcodeprivate").innerHTML = ninja.qrCode.createTableHtml(btcKey.getBitcoinWalletImportFormat(0));
- document.getElementById("detailqrcodeprivatecomp").innerHTML = ninja.qrCode.createTableHtml(btcKey.getBitcoinWalletImportFormat(1));
+ document.getElementById("detailqrcodepublic").innerHTML = ninja.qrCode.createTableHtml(btcKey.getBitcoinAddress());
+ document.getElementById("detailqrcodepubliccomp").innerHTML = ninja.qrCode.createTableHtml(btcKey.getBitcoinAddressCompressed());
+ document.getElementById("detailqrcodeprivate").innerHTML = ninja.qrCode.createTableHtml(btcKey.getBitcoinWalletImportFormat());
+ document.getElementById("detailqrcodeprivatecomp").innerHTML = ninja.qrCode.createTableHtml(btcKey.getBitcoinWalletImportFormatCompressed());
}
}