diff --git a/Gruntfile.js b/Gruntfile.js index 22bce2c..d5bb255 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -37,6 +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: "//main.css", file: "./src/main.css" } ] } diff --git a/src/bitaddress-ui.html b/src/bitaddress-ui.html index 6def813..cc7c970 100644 --- a/src/bitaddress-ui.html +++ b/src/bitaddress-ui.html @@ -144,6 +144,13 @@
+
+ +
@@ -472,6 +479,15 @@ + + + + + + + diff --git a/src/janin.walletmanager.js b/src/janin.walletmanager.js new file mode 100644 index 0000000..0b5c746 --- /dev/null +++ b/src/janin.walletmanager.js @@ -0,0 +1,67 @@ +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(); + return (ECKey.privateKeyPrefix == _privateKeyPrefix) ? + (/^5[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{50}$/.test(key)) : + (/^9[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{50}$/.test(key)); + }; + + // 52 characters base58 + Bitcoin.ECKey.isCompressedWalletImportFormat = function (key) { + key = key.toString(); + return (ECKey.privateKeyPrefix == _privateKeyPrefix) ? + (/^[LK][123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test(key)) : + (/^c[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test(key)); + }; + + ninja.wallets.singlewallet.generateNewAddressAndKey(); +}