diff --git a/Gruntfile.js b/Gruntfile.js index d5bb255..e1bae17 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -37,7 +37,7 @@ module.exports = function (grunt) { { token: "//ninja.detailwallet.js", file: "./src/ninja.detailwallet.js" }, { token: "//qrcode.js", file: "./src/qrcode.js" }, { token: "//securerandom.js", file: "./src/securerandom.js" }, - { token: "//janin.walletmanager.js", file: "./src/janin.walletmanager.js" }, + { token: "//janin.currency.js", file: "./src/janin.currency.js" }, { token: "//main.css", file: "./src/main.css" } ] } diff --git a/bitaddress.org.html b/bitaddress.org.html index 2de6df5..c84f740 100644 --- a/bitaddress.org.html +++ b/bitaddress.org.html @@ -5131,8 +5131,6 @@ Bitcoin.ECKey = (function () { this.compressed = (this.compressed == undefined) ? !!ECKey.compressByDefault : this.compressed; }; - ECKey.privateKeyPrefix = 0x80; // mainnet 0x80 testnet 0xEF - /** * Whether public keys should be returned compressed by default. */ @@ -5220,7 +5218,7 @@ Bitcoin.ECKey = (function () { // Sipa Private Key Wallet Import Format ECKey.prototype.getBitcoinWalletImportFormat = function () { var bytes = this.getBitcoinPrivateKeyByteArray(); - bytes.unshift(ECKey.privateKeyPrefix); // prepend 0x80 byte + bytes.unshift(janin.selectedCurrency.privateKeyPrefix); // prepend private key prefix if (this.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)); @@ -5282,7 +5280,8 @@ Bitcoin.ECKey = (function () { throw "Checksum validation failed!"; } var version = hash.shift(); - if (version != ECKey.privateKeyPrefix) { + // TODO: detect currency + if (version != janin.selectedCurrency.privateKeyPrefix) { throw "Version " + version + " not supported!"; } return hash; @@ -5302,7 +5301,8 @@ Bitcoin.ECKey = (function () { throw "Checksum validation failed!"; } var version = hash.shift(); - if (version != ECKey.privateKeyPrefix) { + // TODO: detect currency + if (version != janin.selectedCurrency.privateKeyPrefix) { throw "Version " + version + " not supported!"; } hash.pop(); @@ -5318,17 +5318,13 @@ Bitcoin.ECKey = (function () { // 51 characters base58, always starts with a '5' ECKey.isWalletImportFormat = function (key) { key = key.toString(); - return (ECKey.privateKeyPrefix == 0x80) ? - (/^5[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{50}$/.test(key)) : - (/^9[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{50}$/.test(key)); + return janin.selectedCurrency.WIF_RegExtest(key); }; // 52 characters base58 ECKey.isCompressedWalletImportFormat = function (key) { key = key.toString(); - return (ECKey.privateKeyPrefix == 0x80) ? - (/^[LK][123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test(key)) : - (/^c[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test(key)); + return janin.selectedCurrency.CWIF_RegExtest(key); }; // 44 characters @@ -5995,6 +5991,13 @@ body { font-family: Arial; }
+
+ +
@@ -6295,7 +6298,85 @@ body { font-family: Arial; }
+ + @@ -479,15 +482,6 @@ - - - - - - - diff --git a/src/bitcoinjs-lib.eckey.js b/src/bitcoinjs-lib.eckey.js index 901ced2..42a3a08 100644 --- a/src/bitcoinjs-lib.eckey.js +++ b/src/bitcoinjs-lib.eckey.js @@ -43,8 +43,6 @@ Bitcoin.ECKey = (function () { this.compressed = (this.compressed == undefined) ? !!ECKey.compressByDefault : this.compressed; }; - ECKey.privateKeyPrefix = 0x80; // mainnet 0x80 testnet 0xEF - /** * Whether public keys should be returned compressed by default. */ @@ -132,7 +130,7 @@ Bitcoin.ECKey = (function () { // Sipa Private Key Wallet Import Format ECKey.prototype.getBitcoinWalletImportFormat = function () { var bytes = this.getBitcoinPrivateKeyByteArray(); - bytes.unshift(ECKey.privateKeyPrefix); // prepend 0x80 byte + bytes.unshift(janin.selectedCurrency.privateKeyPrefix); // prepend private key prefix if (this.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)); @@ -194,7 +192,8 @@ Bitcoin.ECKey = (function () { throw "Checksum validation failed!"; } var version = hash.shift(); - if (version != ECKey.privateKeyPrefix) { + // TODO: detect currency + if (version != janin.selectedCurrency.privateKeyPrefix) { throw "Version " + version + " not supported!"; } return hash; @@ -214,7 +213,8 @@ Bitcoin.ECKey = (function () { throw "Checksum validation failed!"; } var version = hash.shift(); - if (version != ECKey.privateKeyPrefix) { + // TODO: detect currency + if (version != janin.selectedCurrency.privateKeyPrefix) { throw "Version " + version + " not supported!"; } hash.pop(); @@ -230,17 +230,13 @@ Bitcoin.ECKey = (function () { // 51 characters base58, always starts with a '5' ECKey.isWalletImportFormat = function (key) { key = key.toString(); - return (ECKey.privateKeyPrefix == 0x80) ? - (/^5[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{50}$/.test(key)) : - (/^9[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{50}$/.test(key)); + return janin.selectedCurrency.WIF_RegExtest(key); }; // 52 characters base58 ECKey.isCompressedWalletImportFormat = function (key) { key = key.toString(); - return (ECKey.privateKeyPrefix == 0x80) ? - (/^[LK][123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test(key)) : - (/^c[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test(key)); + return janin.selectedCurrency.CWIF_RegExtest(key); }; // 44 characters diff --git a/src/janin.currency.js b/src/janin.currency.js new file mode 100644 index 0000000..9b171cd --- /dev/null +++ b/src/janin.currency.js @@ -0,0 +1,75 @@ +var janin = {}; + +janin.currency = { + createCurrency: function (name, networkVersion, privateKeyPrefix, WIF_Start, CWIF_Start) { + var currency = {}; + currency.name = name; + currency.networkVersion = networkVersion; + currency.privateKeyPrefix = privateKeyPrefix; + currency.WIF_Start = WIF_Start; + currency.CWIF_Start = CWIF_Start; + return currency; + }, + + name: function() { + return janin.selectedCurrency.name; + }, + + networkVersion: function() { + return janin.selectedCurrency.networkVersion; + }, + + privateKeyPrefix: function() { + return janin.selectedCurrency.privateKeyPrefix; + }, + + WIF_RegEx: function() { + return new RegExp("^" + janin.selectedCurrency.WIF_Start + "[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{50}$"); + }, + + CWIF_RegEx: function() { + return new RegExp("^" + janin.selectedCurrency.CWIF_Start + "[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$"); + }, + + useCurrency: function(currency) { + janin.selectedCurrency = currency; + + // TODO: regenerate/reset current wallet (single, vanity ...) + }, + +}; + +janin.currencies = [ + janin.currency.createCurrency ("Bitcoin", 0x00, 0x80, "5", "[LK]"), + janin.currency.createCurrency ("Dogecoin", 0x1e, 0x9e, "6", "T"), + janin.currency.createCurrency ("Litecoin", 0x30, 0xb0, "6", "T") + ]; + +janin.selectedCurrency = janin.currencies[0]; + +/* +janin.currency.useCurrencyWallet = function(_networkVersion, _privateKeyPrefix, _walletImportFormatRegEx, _compressedWalletImportRegEx) { + + Bitcoin.Address.networkVersion = _networkVersion; // mainnet + Bitcoin.ECKey.privateKeyPrefix = _privateKeyPrefix; // mainnet 0x80 testnet 0xEF + + // 51 characters base58, always starts with a '5' + Bitcoin.ECKey.isWalletImportFormat = function (key) { + key = key.toString(); + var currencyRegEx = new RegExp(_walletImportFormatRegEx); + var testnetRegEx = new RegExp("^9[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{50}$"); + + return (ECKey.privateKeyPrefix == _privateKeyPrefix) ? (currencyRegEx.test(key)) : (testnetRegEx.test(key)); + }; + + // 52 characters base58 + Bitcoin.ECKey.isCompressedWalletImportFormat = function (key) { + key = key.toString(); + var currencyRegEx = new RegExp(_compressedWalletImportRegEx); + var testnetRegEx = new RegExp("^c[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$"); + + return (ECKey.privateKeyPrefix == _privateKeyPrefix) ? (currencyRegEx.test(key)) : (testnetRegEx.test(key)); + }; + + ninja.wallets.singlewallet.generateNewAddressAndKey(); +}*/ diff --git a/src/janin.walletmanager.js b/src/janin.walletmanager.js deleted file mode 100644 index 82ee96b..0000000 --- a/src/janin.walletmanager.js +++ /dev/null @@ -1,69 +0,0 @@ -var janin = { currency: { - Address: {}, - ECKey: {} - }}; - - -janin.currency.Address.networkVersions = [ - 0x00, // Bitcoin - 0x1e // Dogecoin -]; - -janin.currency.ECKey.privateKeyPrefixes = [ - 0x80, // Bitcoin - 0x9e // Dogecoin -]; - -janin.currency.WalletImportFormatRegEx = [ - "^5[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{50}$", // Bitcoin - "^6[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{50}$" // Dogecoin -]; - -janin.currency.CompressedWalletImportRegEx = [ - "^[LK][123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$", // Bitcoin - "^T[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$" // Dogecoin -]; - - -janin.currency.changeWalletType = function (ddl) { - - var netVersion = janin.currency.Address.networkVersions[ddl.selectedIndex]; - var privKeyPrefix = janin.currency.ECKey.privateKeyPrefixes[ddl.selectedIndex]; - var walletImportRegex = janin.currency.WalletImportFormatRegEx[ddl.selectedIndex]; - var compressedWalletImportRegex = janin.currency.CompressedWalletImportRegEx[ddl.selectedIndex]; - - janin.currency.useCurrencyWallet( - netVersion, - privKeyPrefix, - walletImportRegex, - compressedWalletImportRegex - ); - - -}; - -janin.currency.useCurrencyWallet = function(_networkVersion, _privateKeyPrefix, _walletImportFormatRegEx, _compressedWalletImportRegEx) { - - Bitcoin.Address.networkVersion = _networkVersion; // mainnet - Bitcoin.ECKey.privateKeyPrefix = _privateKeyPrefix; // mainnet 0x80 testnet 0xEF - - // 51 characters base58, always starts with a '5' - Bitcoin.ECKey.isWalletImportFormat = function (key) { - key = key.toString(); - var currencyRegEx = new RegExp(_walletImportFormatRegEx); - var testnetRegEx = new RegExp("^9[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{50}$"); - - return (ECKey.privateKeyPrefix == _privateKeyPrefix) ? (currencyRegEx.test(key)) : (testnetRegEx.test(key)); - }; - - // 52 characters base58 - Bitcoin.ECKey.isCompressedWalletImportFormat = function (key) { - key = key.toString(); - var currencyRegEx = new RegExp(_compressedWalletImportRegEx); - var testnetRegEx = new RegExp("^c[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$"); - - return (ECKey.privateKeyPrefix == _privateKeyPrefix) ? (currencyRegEx.test(key)) : (testnetRegEx.test(key)); - }; - - ninja.wallets.singlewallet.generateNewAddressAndKey(); -} diff --git a/src/ninja.onload.js b/src/ninja.onload.js index 2372b8e..a079b75 100644 --- a/src/ninja.onload.js +++ b/src/ninja.onload.js @@ -11,16 +11,6 @@ if (ninja.getQueryString()["asyncunittests"] == "true" || ninja.getQueryString() if (ninja.getQueryString()["culture"] != undefined) { ninja.translator.translate(ninja.getQueryString()["culture"]); } -// testnet, check if testnet edition should be activated -if (ninja.getQueryString()["testnet"] == "true" || ninja.getQueryString()["testnet"] == "1") { - document.getElementById("testnet").innerHTML = ninja.translator.get("testneteditionactivated"); - document.getElementById("testnet").style.display = "block"; - document.getElementById("detailwifprefix").innerHTML = "'9'"; - document.getElementById("detailcompwifprefix").innerHTML = "'c'"; - Bitcoin.Address.networkVersion = 0x6F; // testnet - Bitcoin.ECKey.privateKeyPrefix = 0xEF; // testnet - ninja.testnetMode = true; -} if (ninja.getQueryString()["showseedpool"] == "true" || ninja.getQueryString()["showseedpool"] == "1") { document.getElementById("seedpoolarea").style.display = "block"; } \ No newline at end of file diff --git a/src/ninja.translator.js b/src/ninja.translator.js index 46c255a..a5afd6b 100644 --- a/src/ninja.translator.js +++ b/src/ninja.translator.js @@ -31,7 +31,6 @@ ninja.translator = { translations: { "en": { // javascript alerts or messages - "testneteditionactivated": "TESTNET EDITION ACTIVATED", "paperlabelbitcoinaddress": "Bitcoin Address:", "paperlabelprivatekey": "Private Key (Wallet Import Format):", "paperlabelencryptedkey": "Encrypted Private Key (Password required)", @@ -52,7 +51,6 @@ ninja.translator = { "es": { // javascript alerts or messages - "testneteditionactivated": "Testnet se activa", "paperlabelbitcoinaddress": "Dirección Bitcoin:", "paperlabelprivatekey": "Clave privada (formato para importar):", "paperlabelencryptedkey": "Clave privada cifrada (contraseña necesaria)", @@ -186,7 +184,6 @@ ninja.translator = { "fr": { // javascript alerts or messages - "testneteditionactivated": "ÉDITION TESTNET ACTIVÉE", "paperlabelbitcoinaddress": "Adresse Bitcoin:", "paperlabelprivatekey": "Clé Privée (Format d'importation de porte-monnaie):", "paperlabelencryptedkey": "Encrypted Private Key (Password required)", //TODO: please translate @@ -320,7 +317,6 @@ ninja.translator = { "el": { // javascript alerts or messages - "testneteditionactivated": "ΕΝΕΡΓΗ ΕΚΔΟΣΗ TESTNET", "paperlabelbitcoinaddress": "Διεύθυνση Bitcoin:", "paperlabelprivatekey": "Προσωπικό Κλειδί (Μορφή εισαγωγής σε πορτοφόλι):", "paperlabelencryptedkey": "Encrypted Private Key (Password required)", //TODO: please translate @@ -454,7 +450,6 @@ ninja.translator = { "it": { // javascript alerts or messages - "testneteditionactivated": "TESTNET EDITION ATTIVATO", "paperlabelbitcoinaddress": "Indirizzo Bitcoin:", "paperlabelprivatekey": "Chiave privata (Wallet Import Format):", "paperlabelencryptedkey": "Chiave privata criptata (password richiesta)", @@ -589,7 +584,6 @@ ninja.translator = { "de": { // javascript alerts or messages - "testneteditionactivated": "TESTNET AKTIVIERT", "paperlabelbitcoinaddress": "Bitcoin-Adresse:", "paperlabelprivatekey": "Privater Schlüssel (Wallet Import Format):", "paperlabelencryptedkey": "Verschlüsselter privater Schlüssel (Passwort benötigt)", @@ -723,7 +717,6 @@ ninja.translator = { "cs": { // javascript alerts or messages - "testneteditionactivated": "TESTNET aktivován", "paperlabelbitcoinaddress": "Bitcoin adresa:", "paperlabelprivatekey": "Soukromý klíč (WIF – Formát pro import do peněženky):", "paperlabelencryptedkey": "Šifrovaný soukromý klíč (Vyžadováno heslo)",